Our next task is adding the first cat to our virtual shelter.
It should be a POST request, where the body of the request may look something like this: {"name": "Binky", "age": 4}.
If you are familiar with tools such as curl or Postman to issue POST requests, that's great. If not, we'll write a test in the next section that will check exactly that scenario.
The first thing we'll need to do is add the following line after we initialize our router:
router.route().handler(BodyHandler.create())
This will tell Vert.x to parse the request body into JSON for any request. Another way would be to use router.route("/*").
Now, let's figure out what our URL should look like. It is good practice to have our API URLs versioned, so we would like it to be as follows:
api/v1/cats
So, we can assume the following:
- GET...