Migrating/Updating my TinyDB MAC API – FastAPI Docs Page

When you begin exploring APIs to work with, you’ll find that many come with outstanding documentation and offer live examples. One of the things that made FastAPI so intriguing to me is that they offer this right out of the box.

In the previous post, I showed how to make several API endpoints and you may have noticed that I skipped over was the root “/” of my API. In my projects, I use this endpoint to display a small message, share the version number, and provide a link to my API documentation. The code for this is quite simple:

@app.get("/")
# Root of API that shows version, docs, and a welcome message
async def api_root():
    return {"Welcome": "This API will display information about MAC addresses on your network",
            "Documentation": "http://127.0.0.1:8000/docs", "Version": '0.1'}

Depending on your project, you may want to customize the documentation page (more on that in a future post). For our testing purposes now, our local address is just fine. By following the provided link, you’ll see a page listing the API options you’ve created. In my case, it looks like this:

Each option includes a dropdown with descriptions, parameter schemas, and interactive capabilities. Here’s a small example of me testing the “/current_macs” endpoint:

FastAPI allows you to customize descriptions, provide examples, define schemas, and more. For a small home project like mine, I keep things fairly simple. However, for larger projects that you might share with others, you can add detailed information to better help others more effectively consume your API.