Skip to content

Instantly share code, notes, and snippets.

@ProfAvery
Created July 17, 2025 00:56
Show Gist options
  • Save ProfAvery/04ac7c6925b184d48f4891af35d93b34 to your computer and use it in GitHub Desktop.
Save ProfAvery/04ac7c6925b184d48f4891af35d93b34 to your computer and use it in GitHub Desktop.
California State University, Fullerton - CPSC 449 - Web Back-End Engineering

CPSC 449 - Web Back-End Engineering

Exercise 1 - Fall 2023

This exercise may be completed individually, or in a pair with another student. If you work with another student, only one of you needs to submit via Canvas.

Exercise

By the end of this exercise you will have written Node.js programs to obtain information from REST and GraphQL APIs for an online music store.

Setup

Complete the following steps to set up REST and GraphQL APIs for an online music store.

Obtain the Chinook sample database

Download and extract the chinook SQLite sample database from sqlitetutorial.net.

wget https://www.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip  
unzip chinook.zip

Install REST and GraphQL API servers

Install the soul server to expose a REST API for an existing database.

npm install --global soul-cli

Install the tuql server to expose a GraphQL API for an existing database.

npm install --global tuql

Start the API servers

In separate terminal windows, start API servers for the chinook database

soul --database chinook.db --studio   
tuql --db chinook.db --graphiql

Querying data with REST and GraphQL

Access the admin interfaces

Check that you can access the Soul Studio GUI, the Soul API documentation, and the GraphiQL IDE for tuql by browsing to the following URLs:

Retrieve a record

Visit the following URL to retrieve information about the first artist in the database using the REST API:

http://localhost:8000/api/tables/artists/rows/1

Note: in Firefox, you can use the “Raw Data” tab and the “Pretty Print” button to view the output in JSON.

In GraphiQL, execute the following query to retrieve the same information from the GraphQL API:

query {  
  artist(where: {artistId: 1}) {  
    artistId,  
    name  
  }  
}

For details on filtering GraphQL query results using the where clause, see the documentation for the Where in the Sequelize ORM documentation.

Write more complicated queries

Using the database diagram for reference, write queries using both APIs to retrieve the following:

  1. Albums by the artist “Red Hot Chili Peppers.”

  2. Genres associated with the artist “U2.”

  3. Names of tracks on the playlist “Grunge” and their associated artists and albums.

Note: while the results for each query can be retrieved in a single GraphQL API call, you will likely need to make several REST API calls for each query. You may wish to save these calls with a desktop GUI tool such as Insomnia or Postman.

Making API calls from Node.js

Use Axios or the Fetch API to write command-line JavaScript programs to print out the answers to each of the queries listed above, using both the REST and GraphQL APIs.

Reminder: if you want to use top-level await, your scripts will need to have the .mjs extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment