The first requests
At this point, our Nest.js API is ready to listen to requests (both GET
and POST
) and operate on the data stored in our MongoDB instance based on those requests. In other words, we are ready to read from and write to our database from the API.
Let’s give it a try.
We will start with a GET request to the /entries
endpoint. Obviously, since we haven’t created any entries yet, we should receive an empty array as a response.
> GET /entries HTTP/1.1 > Host: localhost:3000 < HTTP/1.1 200 OK []
Let’s create a new entry by sending a POST
request to the entries
endpoint and including in the request body a JSON object that matches the shape of our previously defined EntrySchema
.
> GET /entries HTTP/1.1 > Host: localhost:3000 | { | "title": "This is our first post", | "body": "Bla bla bla bla bla", | "image": "http://lorempixel.com/400", | "created_at": "2018...