![]() ![]() Now, navigate to the main.py’s folder through the terminal and run the following: uvicorn main:app -reload In other words, a function that returns what we want to get from our API(in our case is a JSON with the message Hello World. ![]() Lastly, we have to define the path operation function. By operation we mean the HTTP methods like GET, POST, PUT and DELETE(in our case the operation is get). That means we have to set the URL path(in our case is ‘/’ but we can set anything like ‘/helloworld’) and its operation. The first step is to import it, and then to create a FastAPI instance(in our case it’s called app).Īfter that, we have to create a path operation. #create a path the path operation functionĪs you can see, there are 4 main steps to create an API with FastAPI. It will return a JSON with the message “Hello World”.Ĭreate a “main.py” file with the following code. Let’s get started by creating the simplest API. We will also need an ASGI server, for production such as Uvicorn. In this post, I will show you how to create some simple GET and POST APIs using Fast API. The only con about Fast API is that it’s relatively new and its community is not so big as other frameworks like Flask but I think it will grow fast as many companies like Microsoft, Netflix, and Uber are already using it. Its key features are that is fast, up to 300% faster to code, fewer bugs, easy to use, and production-friendly. ![]() FastAPI is a modern, python-based high-performance web framework used to create Rest APIs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |