A small application that demonstrates how to use IBM Compose for Redis as a cache for College Scorecard API queries. The application queries the API for college names, then shows the college name and their location on a map using Mapbox.
- Node.js - the application uses the Express framework, so you'll need Node.js installed. Node.js also comes with the npm package manager to install Express and the other libraries the application uses.
- IBM Cloud - Sign up for a free IBM Cloud account. This will allow you to provision an IBM Compose for Redis database.
- Data.Gov API KEY - You can get an API key to use with all of the APIs from Data.Gov. Just sign up for a key using your email, and a key will be sent to you. Then we can use it when making HTTP requests to the College Scorecard API.
- IBM Compose for Redis - Redis is used to store the user query and response data from the College Scorecard API. The database uses the "cache mode", which you'll have to contact IBM Cloud Support to turn on once you've provisioned the database. Cache mode disables the database from auto-scaling, and therefore relies on Redis to evict items from memory.
- Mapbox - You will need a Mapbox access token. Sign up for a Mapbox account then create your own access token.
Once you're in IBM Cloud, just click on Create Resource and look for Compose for Redis. Click on it to get into the service page, then click on Create to create the database.
That will take you to your Compose for Redis management page. You'll see your Redis connection string URI within the Connection Strings panel. Also, click on the tab SSL Certificate and store that certificate in a file called caCert.crt
. We'll use that when making a TLS connection to Redis.
Create a file called .env
to store environment variables. A template for that file is .env.template
in this repository. Copy the contents of the .env.template
file into .env
.
COMPOSE_REDIS_URL=xxxxxxxxxxxxxxxxxxxxxxx
DATAGOV_API_KEY=xxxxxxxxxxxxxxxxxxxxxxx
Then set COMPOSE_REDIS_URL
to your IBM Compose for Redis URI and DATAGOV_API_KEY
to the Data.Gov API key that was emailed to you.
Both of these variables are used inside the server.js
file as:
const apiKey = process.env.DATAGOV_API_KEY;
const connectionString = process.env.COMPOSE_REDIS_URL;
Next, within public/js/results.js
, substitute the Mapbox access token with your own:
mapboxgl.accessToken = "pk.eyJ1IjoiYWFsZ2VyIiwiYSI6ImNqMzB2OGJlbjAwMW8zM2s4cWVsY3IybWIifQ.9qDiHbV9N5ezaQ8czC9gew";
This access token only serves as an example.
Install the Node.js packages included in package.json
:
npm install
Run the application
npm start
In your preferred browser, type in localhost:9000
to interact with the application.