Documenting Museum API Endpoints

Understanding the Problem

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:

Devising a Plan

To solve this systematically, we will:

  1. Set up Postman and start the local server
  2. Examine server code for endpoint implementations
  3. Test each endpoint using Postman
  4. Document findings in answers.json
  5. Run tests to verify documentation

Implementing the Solution

Setup Procedures

  1. Start the server: Run 'npm start' in terminal
  2. Open Postman and create a new collection
  3. Set base URL to http://localhost:5000
  4. Open Chrome DevTools Network tab for monitoring requests

Testing Procedures

  1. For each endpoint:
  2. Document in answers.json:

Example Implementation

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
            }
        ]
    }
}

Looking Back and Real-World Application

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.

Key Learnings

Further Applications

These skills apply to: