-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Full Stack FastAPI, React, and MongoDB - Second Edition
By :
FastAPI is a modern and performant web framework for building APIs. Built by Sebastian Ramirez, it uses the newest features of the Python programming language, such as type hinting and annotations, the async – await syntax, Pydantic models, web socket support, and more.
If you are not familiar with APIs, let’s get into it in more depth by understanding what an API is. An application programming interface (API) is used to enable some kind of interaction between different pieces of software, and they communicate using Hypertext Transfer Protocol (HTTP) through a cycle of requests and responses. Therefore, an API is, as its name suggests, an interface. Via this interface, humans or machines interact with an application or a service. Every API provider should have an interface that is well suited for the type of data that they provide; for instance, a weather forecasting station provides an API that lists the temperatures and humidity levels for a certain location. Sports sites provide statistical data about the games that are being played. A pizza delivery API will provide you with the selected ingredients, the price, and the estimated time of arrival.
APIs touch every aspect of your life, for example, transmitting medical data, enabling fast communications between applications, and even used in tractors in fields. APIs are what make today’s web run and, put simply, are the best form of information exchange.
This chapter will not go over the rigorous definitions of REST APIs, but just list some of their most important features:
There are numerous reasons why MongoDB chose FastAPI for their REST API layer, even though it’s new compared to other Python frameworks. Here are some of the reasons:
asyncio module into Python.Also, getting started is relatively simple:
pip install fastapi
In order to get at least a basic idea of what coding with FastAPI looks like, let’s take a look at a minimal API:
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get(“/”)
async def root():
return {“message”: “Hello World”} The preceding few lines of code define a minimal API with a single endpoint (/) that responds to a GET request with the message Hello world. You can instantiate a FastAPI class and use decorators to tell the server which HTTP methods should trigger which function for a response.