How it works...

Now let's test our new API:

  1. If we go to http://localhost:3000/api, we are going to display a list of the endpoints. This is optional, but it is useful as a reference for developers:
  1. If you go to http://localhost:3000/api/posts, you will see all the posts:
  1. Also, if you hit http://localhost:3000/api/post/1, you will get the first post of the list:
  1. Finally, if you try to get a post that does not exist in our data (http://localhost:3000/api/post/99 ...

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.