Software Engineer · Teacher · Author · Vegan

Express and Knex API

For this assignment, build the following API endpoints with Express and Knex. The responses for each endpoint should match the example structures exactly. The JSON keys should be the same. The only thing that will vary is the data.

GET /api/artists

This endpoint should return all artists sorted by the artist name (A-Z). Map the results returned from the database so that the response looks like the following:

  { "id": "1", "name": "AC/DC" },
  { "id": "2", "name": "Accept" },
  // ...

You might find helpful.

GET /api/artists?filter=a

Modify GET /api/artists so that it accepts a query string parameter called filter. If this query string param is present in the request, only return the artists where the name contains that value. This should be case insensitive and also sorted by the artist name (A-Z). If the query string param isn’t present in the request, return all artists.

You might find the following links helpful:

GET /api/artists/:id

This endpoint should return the artist with an ArtistId of :id and the albums for that artist.

  "artist": {
    "id": 1,
    "name": "..."
  "albums": [
      "id": "...",
      "title": "..."
    // ...

If the artist isn’t found, return a 404 response with an empty response body.


Next, deploy your API to Heroku. In order to deploy your app to Heroku, you’ll need to make 2 changes. First, change the app.listen(8000) line to app.listen(process.env.PORT || 8000). Second, add a start script to your package.json:

  "scripts": {
    "start": "node index.js"

With the above code, you can run npm start from the command line, and it will run node index.js. Heroku will run npm start when it sees a package.json file. If your file isn’t index.js, either change it to index.js or change the command.

Lastly, create a file with links to all of your endpoints.