diff --git a/docs/en/docs/deployment/deta.md b/docs/en/docs/deployment/deta.md index c0dc3336a..04fc04c0c 100644 --- a/docs/en/docs/deployment/deta.md +++ b/docs/en/docs/deployment/deta.md @@ -1,15 +1,22 @@ -# Deploy FastAPI on Deta +# Deploy FastAPI on Deta Space -In this section you will learn how to easily deploy a **FastAPI** application on Deta using the free plan. 🎁 +In this section you will learn how to easily deploy a **FastAPI** application on Deta Space, for free. 🎁 -It will take you about **10 minutes**. +It will take you about **10 minutes** to deploy an API that you can use. After that, you can optionally release it to anyone. + +Let's dive in. !!! info - Deta is a **FastAPI** sponsor. 🎉 + Deta is a **FastAPI** sponsor. 🎉 -## A basic **FastAPI** app +## A simple **FastAPI** app -* Create a directory for your app, for example, `./fastapideta/` and enter into it. +* To start, create an empty directory with the name of your app, for example `./fastapi-deta/`, and then navigate into it. + +```console +$ mkdir fastapi-deta +$ cd fastapi-deta +``` ### FastAPI code @@ -37,14 +44,12 @@ Now, in the same directory create a file `requirements.txt` with: ```text fastapi +uvicorn[standard] ``` -!!! tip - You don't need to install Uvicorn to deploy on Deta, although you would probably want to install it locally to test your app. - ### Directory structure -You will now have one directory `./fastapideta/` with two files: +You will now have a directory `./fastapi-deta/` with two files: ``` . @@ -52,22 +57,23 @@ You will now have one directory `./fastapideta/` with two files: └── requirements.txt ``` -## Create a free Deta account +## Create a free **Deta Space** account -Now create a free account on Deta, you just need an email and password. +Next, create a free account on Deta Space, you just need an email and password. + +You don't even need a credit card, but make sure **Developer Mode** is enabled when you sign up. -You don't even need a credit card. ## Install the CLI -Once you have your account, install the Deta CLI: +Once you have your account, install the Deta Space CLI: === "Linux, macOS"
+
+Now run `space login` from the Space CLI. Upon pasting the token into the CLI prompt and pressing enter, you should see a confirmation message.
+
+Click on the new app called `fastapi-deta`, and it will open your API in a new browser tab on a URL like `https://fastapi-deta-gj7ka8.deta.app/`.
+
+You will get a JSON response from your FastAPI app:
```JSON
{
@@ -185,74 +240,152 @@ You will see the JSON response from your FastAPI app:
}
```
-And now go to the `/docs` for your API, in the example above it would be `https://qltnci.deta.dev/docs`.
+And now you can head over to the `/docs` of your API. For this example, it would be `https://fastapi-deta-gj7ka8.deta.app/docs`.
-It will show your docs like:
-
-
+
## Enable public access
-By default, Deta will handle authentication using cookies for your account.
+Deta will handle authentication for your account using cookies. By default, every app or API that you `push` or install to your Space is personal - it's only accessible to you.
-But once you are ready, you can make it public with:
+But you can also make your API public using the `Spacefile` from earlier.
+
+With a `public_routes` parameter, you can specify which paths of your API should be available to the public.
+
+Set your `public_routes` to `"*"` to open every route of your API to the public:
+
+```yaml
+v: 0
+micros:
+ - name: fastapi-deta
+ src: .
+ engine: python3.9
+ public_routes:
+ - "/*"
+```
+
+Then run `space push` again to update your live API on Deta Space.
+
+Once it deploys, you can share your URL with anyone and they will be able to access your API. 🚀
+
+## HTTPS
+
+Congrats! You deployed your FastAPI app to Deta Space! 🎉 🍰
+
+Also, notice that Deta Space correctly handles HTTPS for you, so you don't have to take care of that and can be sure that your users will have a secure encrypted connection. ✅ 🔒
+
+## Create a release
+
+Space also allows you to publish your API. When you publish it, anyone else can install their own copy of your API, in their own Data Space cloud.
+
+To do so, run `space release` in the Space CLI to create an **unlisted release**:
+Add some logging functionality to your app by adding a `print` statement to your `main.py` file.
+
+```py
+from fastapi import FastAPI
+
+app = FastAPI()
+
+
+@app.get("/")
+def read_root():
+ return {"Hello": "World"}
+
+
+@app.get("/items/{item_id}")
+def read_item(item_id: int):
+ print(item_id)
+ return {"item_id": item_id}
+```
+
+The code within the `read_item` function includes a print statement that will output the `item_id` that is included in the URL. Send a request to your _path operation_ `/items/{item_id}` from the docs UI (which will have a URL like `https://fastapi-deta-gj7ka8.deta.app/docs`), using an ID like `5` as an example.
+
+Now go to your Space's Canvas. Click on the context menu (`...`) of your live app instance, and then click on **View Logs**. Here you can view your app's logs, sorted by time.
+
+
## Learn more
-At some point, you will probably want to store some data for your app in a way that persists through time. For that you can use Deta Base, it also has a generous **free tier**.
+At some point, you will probably want to store some data for your app in a way that persists through time. For that you can use Deta Base and Deta Drive, both of which have a generous **free tier**.
+
+You can also read more in the Deta Space Documentation.
+
+!!! tip
+ If you have any Deta related questions, comments, or feedback, head to the Deta Discord server.
-You can also read more in the Deta Docs.
## Deployment Concepts
-Coming back to the concepts we discussed in [Deployments Concepts](./concepts.md){.internal-link target=_blank}, here's how each of them would be handled with Deta:
+Coming back to the concepts we discussed in [Deployments Concepts](./concepts.md){.internal-link target=_blank}, here's how each of them would be handled with Deta Space:
-* **HTTPS**: Handled by Deta, they will give you a subdomain and handle HTTPS automatically.
-* **Running on startup**: Handled by Deta, as part of their service.
-* **Restarts**: Handled by Deta, as part of their service.
-* **Replication**: Handled by Deta, as part of their service.
-* **Memory**: Limit predefined by Deta, you could contact them to increase it.
-* **Previous steps before starting**: Not directly supported, you could make it work with their Cron system or additional scripts.
+- **HTTPS**: Handled by Deta Space, they will give you a subdomain and handle HTTPS automatically.
+- **Running on startup**: Handled by Deta Space, as part of their service.
+- **Restarts**: Handled by Deta Space, as part of their service.
+- **Replication**: Handled by Deta Space, as part of their service.
+- **Authentication**: Handled by Deta Space, as part of their service.
+- **Memory**: Limit predefined by Deta Space, you could contact them to increase it.
+- **Previous steps before starting**: Can be configured using the `Spacefile`.
!!! note
- Deta is designed to make it easy (and free) to deploy simple applications quickly.
+ Deta Space is designed to make it easy and free to build cloud applications for yourself. Then you can optionally share them with anyone.
It can simplify several use cases, but at the same time, it doesn't support others, like using external databases (apart from Deta's own NoSQL database system), custom virtual machines, etc.
- You can read more details in the Deta docs to see if it's the right choice for you.
+ You can read more details in the Deta Space Documentation to see if it's the right choice for you.
diff --git a/docs/en/docs/img/deployment/deta/image03.png b/docs/en/docs/img/deployment/deta/image03.png
new file mode 100644
index 000000000..232355658
Binary files /dev/null and b/docs/en/docs/img/deployment/deta/image03.png differ
diff --git a/docs/en/docs/img/deployment/deta/image04.png b/docs/en/docs/img/deployment/deta/image04.png
new file mode 100644
index 000000000..88898e0f2
Binary files /dev/null and b/docs/en/docs/img/deployment/deta/image04.png differ
diff --git a/docs/en/docs/img/deployment/deta/image05.png b/docs/en/docs/img/deployment/deta/image05.png
new file mode 100644
index 000000000..590f6f5e4
Binary files /dev/null and b/docs/en/docs/img/deployment/deta/image05.png differ
diff --git a/docs/en/docs/img/deployment/deta/image06.png b/docs/en/docs/img/deployment/deta/image06.png
new file mode 100644
index 000000000..f5828bfda
Binary files /dev/null and b/docs/en/docs/img/deployment/deta/image06.png differ