Request body
In the previous sections, we learned how to use the APIRouter
class and Pydantic models for request body validations and discussed path and query parameters.
A request body is data that you send to your API using a routing method such as POST
and UPDATE
.
POST and UPDATE
The POST
method is used when an insertion into the server is to be made, and the UPDATE
method is used when existing data in the server is to be updated.
Let’s take a look at a POST
request from earlier on in the chapter:
(venv)$ curl -X 'POST' \ 'http://127.0.0.1:8000/todo' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "id": 2, "item": "Validation models help with input types" }'
In the preceding request, the request body is as follows:
{ "id": 2, "item"...