From the course: Advanced Python: Practical Database Examples

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Create an API contract

Create an API contract

- When a client wants to put a new piece of data into our books database, they'll use our API. Currently, our API only has a hello world type endpoint where the client runs a get request to the home route. We need to add a new endpoint that allows the client to add a book to our database. GET is a type of HTTP method used with REST APIs. It's used to request information. Other types of HTTP methods also exist such as POST, PUT, DELETE, PATCH, and a few others. In this chapter, we'll be focusing on POST. When a POST request is made to an API, typically it creates a new resource. In our case, it will create a new book and add it to our database. For the POST endpoint, we need to create a contract for how the client will send us the data. The client will send a POST request to the book endpoint or the book route. In the request, the client will also send a request payload. That's data sent with the request. This payload…

Contents