GET /posts. This endpoint can be tested with your browser. Go to http://localhost:3000/api/posts. I have manually inserted three rows with the createPost method:
If you want to test it on Postman, then write the same URL (http://localhost:3000/api/posts), select the GET method, and click on the Send button:
GET /post/:slug
This endpoint is also a GET, and you need to pass the slug (the friendly URL) in the URL. For example, the slug of the first row, My blog post 1, is my-blog-post-1. A slug is a friendly URL that has the same value as the title but in lowercase, without special characters and the spaces are replaces with dashes (-). In our model, we defined our slug as a unique field, which means that there cannot be more than one post with the same slug.
Let's go to http://localhost:3000/api/post/my-blog-post-1 in the browser. If the slug exists in the database you will see the information:
But if you try to view a slug that does not exist in the database you will get this error: