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.
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.
Complete the following steps to set up REST and GraphQL APIs for an online music store.
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 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
In separate terminal windows, start API servers for the chinook database
soul --database chinook.db --studio
tuql --db chinook.db --graphiql
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:
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.
Using the database diagram for reference, write queries using both APIs to retrieve the following:
-
Albums by the artist “Red Hot Chili Peppers.”
-
Genres associated with the artist “U2.”
-
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.
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.