HTTP Apps Made Easier with FastApp
pip install fastapppip install fastapp[example]fastapp serve-debug fastapp.app.example:appCreate a Python File with Endpoints, we'll call this main.py:
from datetime import datetime
from fastapp.app import app
@app.get("/hello")
def custom_endpoint() -> dict:
""""
This is a Custom API Endpoint
"""
return dict(timestamp=datetime.now(),
hello="world")Then, using the FastApp CLI we can serve this App:
fastapp serve-debug main:app...or via docker:
docker run --rm -it \
--publish 8080:8080 \
--volume ${PWD}/main.py:/root/fastapp/main.py \
juftin/fastapp:latest \
serve-debug main:appTest out our new endpoint:
curl \
--request GET \
--header "Content-Type: application/json" \
http://localhost:8080/helloAlternatively, if we want to serve this app using Gunicorn, Nginx, and the UvicornWorker we can use
the serve command:
fastapp serve main:appI prefer doing this within a docker container so you don't have to run Nginx on the host machine:
docker run --rm -it \
--publish 8080:8080 \
--volume ${PWD}/main.py:/root/fastapp/main.py \
juftin/fastapp:latest \
serve main:app