

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Documentation
incomplete
2: How to Document
incomplete
3: Sorting Chirps
incomplete
4: Adding a README
incomplete
This lesson's interactive features are locked, please to keep using them
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.
Update the GET /api/chirps endpoint. It should accept an optional query parameter called authorId.
For example:
GET http://localhost:8080/api/chirps?authorId=1
Be sure to filter by author ID at the database level, not in memory! That will be more efficient on large datasets.
Run and submit the CLI tests.
The Request object has query property. It can contain anything, so it's a good idea to validate it before using it.
let authorId = "";
let authorIdQuery = req.query.authorId;
if (typeof authorIdQuery === "string") {
authorId = authorIdQuery;
}