Implementing an endpoint to retrieve all notes using HTTP verb GET
To retrieve all notes, we will implement an endpoint that meets specific requirements. Let's make a list of these requirements to gain an understanding of what the request and response should look like.
The request is expected to meet the following criteria:
- The HTTP method will be
GET. - The HTTP route will be
/notes/.
The response is expected to meet the following criteria:
- Select all of the notes from the database using the built-in
orm-based syntax. - Encode the notes retrieved from the database into JSON format, which results in a JSON array.
- The status code will show
200, Ok. - The response body will have a JSON array of encoded
Notecollection. - The
Content-Typeresponse header will be set toapplication/json.
With this information, we will go on to define a route to retrieve all notes.
Defining a route to retrieve all notes
Now, we will create a struct...