This is a quick post showing how to create a “Hello, World” example in FastAPI.
Similar to the example Hello World, In Flask, with FastAPI we instantiate an app which contains methods that decorate other functions which will be used to returns responses. Finally, I used uvicorn
to actually run the application at a given host and port.
from fastapi import FastAPI
= FastAPI()
app
@app.get("/")
def read_root():
return {"message": "Hello, World!"}
if __name__ == '__main__':
import uvcorn
="127.0.0.1", port=8000) uvicorn.run(app, host
That’s all there is for this minimum working example.