Designing
and implementing REST APIs
9
return {"message": "post does not exist"}
else:
del discussion_posts[id]
return {"message": "main post deleted"}
All path operations require a unique endpoint URL in the
str
format. A good practice is to start all
URLs with
the same top-level base path, such as
/ch01
, and then differ when reaching their respective
subdirectories. After
running the uvicorn server, we can check and validate whether all our URLs
are valid and running by accessing the documentation URL,
http://localhost:8000/docs
.
This
path will show us a
OpenAPI
dashboard, as shown in
Figure 1.2, listing all the API methods
created for the application. Discussions on the
OpenAPI will be covered in Chapter 9, Utilizing Other
Advanced Features.
Figure 1.2 – A Swagger OpenAPI dashboard
After
creating the endpoint services, let us scrutinize how FastAPI manages its incoming request
body and the outgoing response.
Setting Up FastAPI for Starters
10
Chia sẻ với bạn bè của bạn: