From the course: Build REST APIs with FastAPI

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Running the server

Running the server

You have your code written, right? You wrote the health function that returns a dictionary with None. When someone does a get to /health, this function should be called. FastAPI itself does not implement a web server. It actually talks something known as the ASGI protocol. And there are web server who talks this ASGI protocol and they transfer the HTTP request into FastAPI using that. And by default, FastAPI is using one web server which is called Uvicorn. To make it easy for you, FastAPI comes with a FastAPI command line utility, which helps you when you're developing. So fastapi and then it's Ch02/02_02/server.py. And I forgot to run. You can use a --help to see what's available, but right now I'm going to do run. And this is now starting the server. And you see the server is running on port 8000. So I'm going to use another command. And then I'm doing curl http://localhost:8000/health and I'm going to get errors. Now if I'm going to change the code, let's say, no db, and then I'm…

Contents