- Data Validation - In FastAPI you define the types of data your API is expecting. Traditionally when we wire a web app in python we don't explictly set what type of information our endpoint will be accepting, this means we have to do alot of data validation, to check and ensure that the tpye of data you recive is matching to the expected type. In FastAPI this is done automatically so if the API gets the wrong type of it will return an error telling us what type of data was recived and what is expected.
- Auto Documentation - Since we are assigning all of the types expected of the API, fastAPI can generate documentation that also works as a "test script", a webpage is generated so we can access it and see all of the API endpoint and what type of input they expect and any description or information.
- Auto Completion and Code Suggestions - If we are working in an IDE like VSCode or Pycharm then we get really good auto-completion because we are defining these types.
pip install fastapipip install uvicorn- Make a new python file and import FastAPI from fastapi e.g.
from fastapi improt FastAPI - To start using the fastAPI we need to create an "app" parameter and assign it the FastAPI method
e.g.
app = FastAPI()
- GET - returns information from the endpoint, "gets" information.
- POST - sending information to the endpoint, or creating something new, e.g "posting" a new user login.
- PUT - update/modifiy exsiting information.
- DELETE - deleting exsiting information.
- "cd" into the directory containing the API script.
- Execute the following command:
uvicorn working:app --reloadThe syntax is as follows:uvicore <name_of_script>:<name_of_app_in_script> --reload. note: the--reloadmeans that uvicorn will constantly reload the server whenever a change is made to the python file that stores that API.