We need to document the request and response components for a painting museum API server. The server manages artists and their paintings, with endpoints for creating, reading, updating, and deleting resources. We need to understand:
To solve this systematically, we will:
Let's examine the "Get all artists" endpoint:
// Server Implementation
if (req.method === "GET" && req.url === "/artists") {
const resBody = JSON.stringify(Object.values(artists));
res.setHeader('Content-Type', 'application/json');
res.write(resBody);
return res.end();
}
// Documentation in answers.json
{
"endpoint": "Get all the artists",
"request": {
"method": "GET",
"URL": "/artists",
"headers": false,
"body": false
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"statusCode": 200,
"body": [
{
"artistId": true,
"name": true
}
]
}
}
This exercise mirrors real-world API documentation tasks. Like a museum curator organizing artwork information, we're organizing our API's interface. The documentation serves as a guide for other developers, similar to how a museum catalog helps visitors understand the collection.
These skills apply to: