Files
archived-starters/examples/fastapi/README.md
Faraz Patankar 5c66af4831 Add frontmatter to all starters (#98)
* add frontmatter to BlitzJS starter

* add frontmatter to all starters

* add plugins and envVars

* fix envVars formatting

* fix key for defaultValue in envVars

* remove unused frontmatter
2021-05-13 02:56:21 -04:00

1.2 KiB

FastAPI-Railway.app

A sample python FastAPI (api app) to run on Railway.app

To setup and run Railway app follow these steps https://docs.railway.app/getting-started

Few things different from the Flask example:

Main difference between Flask and FastAPI is, Flask is WSGI and FastAPI is ASGI so Flask gunicorn wont work with FastAPI, you need to use uvicorn instead of gunicorn.

  • Procfile is modified to call the 'python main.py'
  • main.py uses uvicorn to start the app from main function
  • In uvicorn.run(...) along with the port it needs host="0.0.0.0" # I am not sure why this is required

This sample api includes a random number generator (with min and max limits)

App Routes

Route Root

localhost:8080/ returns {"Hello": "World from FastAPI"}

Route Random (Default)

localhost:8080/random returns a random number between 0 to 9 ex:- {"value":8}

Route Random with min/max

localhost:8080/random?min=100&max500 returns a random number between 100 and 500 ex:- {"value":421}

Let me know if you have any questions @prakis