- FastAPI -> Learn -> Tutorial - User Guide
- Create A REST API with FastAPI, SQLAlchemy and PostgreSQL.
$ conda create -n fastfly python=3.10
$ conda activate fastfly
$ pip install "fastapi[all]"
$ pip install SQLAlchemy
$ pip install psycopg2-binary
$ pip install asyncpg
$ uvicorn main:app --reload
$ curl -X POST localhost:8000/items \
-H "Content-Type: application/json" \
-d '{"id": 1, "name": "Milk", "price": 2000, "description": "Nice milk", "on_offer": true}'
$ curl -X POST https://fastfly.onrender.com/items \
-H "Content-Type: application/json" \
-d '{"id": 1, "name": "Milk", "price": 2000, "description": "Nice milk", "on_offer": true}'
$ curl -X POST localhost:8000/items \
-H "Content-Type: application/json" \
-d '{"id": 2, "name": "Coffee", "price": 5000, "description": "Nice coffee", "on_offer": false}'
$ curl -X PUT localhost:8000/item/1 \
-H "Content-Type: application/json" \
-d '{"id": 1, "name": "Milk", "price": 1500, "description": "Nice milk rebate", "on_offer": true}'
$ curl -X DELETE localhost:8000/item/5 \
-H "Content-Type: application/json" \
-d '{"id": 4, "name": "Coffee", "price": 5000, "description": "Nice coffee", "on_offer": false}'
Follow these intructions: https://stackoverflow.com/a/67596486
Use this repo as a template to deploy a Python FastAPI service on Render.
See https://render.com/docs/deploy-fastapi or follow the steps below:
-
You may use this repository directly or create your own repository from this template if you'd like to customize the code.
-
Create a new Web Service on Render.
-
Specify the URL to your new repository or this repository.
-
Render will automatically detect that you are deploying a Python service and use
pip
to download the dependencies. -
Specify the following as the Start Command.
uvicorn main:app --host 0.0.0.0 --port $PORT
-
Click Create Web Service.
Or simply click:
Thanks to Harish for the inspiration to create a FastAPI quickstart for Render and for some sample code!