chapter six

6 Creating resources

 

In previous chapters we learned a little about using Postman, and in one of those examples we learned how to create new reviews in the FarmStall API. Creating those reviews required executing a POST operation with a request body. Creating reviews happens to be a critical part of this API, what good is a review centric API without the ability to create reviews!

What we’ll be doing this chapter is describing the operation to create new reviews, ie: POST /reviews. In addition to that, we’re going to take a look at GET /reviews/{reviewId}. This GET operation interests us for two reasons, firstly we’d like to confirm that we did indeed create a new review by fetching the same review back again, and secondly we can see how a path parameter works.

Part of the charm of this approach is using the API itself to verify our work.

Similar to a response body, request bodies are described using OpenAPI’s JSON Schema variant and require a media type to indicate the type of data being sent (ie: application/json).

What we’ll be touching on

  • Describe POST /review to create new reviews using a request body
  • Create new reviews using Try-it-out in SwaggerEditor
  • Describe GET /review/{reviewId} including its path parameter
  • Verify that our newly created reviews are really created using SwaggerEditor’s Try-it-out
Figure 6.1. Postman creating a new review
ch06 postman post reviews
Figure 6.2. Where we are
ch06 where we are

6.1  The problem

6.2  Describing POST /reviews with a request body

6.2.1  Where to find request bodies

6.3  Executing operations with request bodies

6.3.1  Adding examples to make try-it-out look pretty

6.4  Describing GET /reviews/{reviewId} with a path parameter

6.4.1  Path parameters

6.4.2  Describing the path parameter

6.5  Verifying our reviews are getting created

6.6  Summary