0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
When you're designing a server-side API, no one is going to know how to interact with it unless you tell them. Are you going to force the front-end developers, mobile developers, or other back-end service teams to sift through your code and reverse engineer your API?
Of course not! You're a good person. You're going to write documentation.
We've talked a lot about how your REST API should follow conventions as much as possible. That said, the conventions are not enough. You still need to document your endpoints. Without documentation, no one will know:
One type of endpoint that's nearly impossible to interact with without documentation is a plural GET
endpoint, that is, an endpoint that returns a list of resources. They often have different sorting, filtering, and pagination features.
For example:
GET http://localhost:8080/api/chirps?author_id=1
Continue sorting the chirps by created_at
in ascending order.
Run and submit the CLI tests.
The http.Request struct has a way to grab the query parameters from the URL:
s := r.URL.Query().Get("author_id")
// s is a string that contains the value of the author_id query parameter
// if it exists, or an empty string if it doesn't
The Boot.dev CLI requires you to be signed in to submit your solution!
Copy/paste one of the following commands into your terminal:
Run
bootdev run c1a4f8aa-de85-45fe-9e70-e49a98e14e3a
Submit
bootdev run c1a4f8aa-de85-45fe-9e70-e49a98e14e3a -s
To run and submit the tests for this lesson, you must have an active Boot.dev membership
Become a member to view solution
Using the Bootdev CLI
The Bootdev CLI is the only way to submit your solution for this type of lesson. We need to be able to run commands in your environment to verify your solution.
You can install it here. It's a Go program hosted on GitHub, so you'll need Go installed as well. Instructions are on the GitHub page.