This repo demonstrates how to run and host a loopback app on Google App Engine.
I modelled the Spotify Web API. Spotify is an online music service that gives you instant access to millions of songs – from old favorites to the latest hits.
I created three models for this demo Albums
, Tracks
and Artists
.
- Albums Model Structure
"artists": [{
  "name": ""
  }],
"album_type": "",
"image": "",
"tracks": [{
  "name": ""
  }],
"release_date": ""
- Tracks Model Structure
"artists": [{
  "name": ""
 }],
"albums": [{
  "name": ""
 }],
"duration": "",
"image": "",
"name": ""
- Artists Model Structure
"name": "",
"popularity": "",
"genres": [{
  "name": ""
  }],
"image": ""
- Note: I used Google Cloud Firestore service as my datastore.
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request POST \
--url https://<YOUR_URL_HERE>.appspot.com/api/albums \
--header 'authorization: Bearer '$JWT \
--header 'content-type: application/json' \
--data '{"name":"Dangerous","artists":[{"name":"Michael Jackson"}],"album_type":"Pop","image":"michaeljackson.png","tracks":[{"name":"Dangerous"}],"release_date":"1991"}'
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request GET \
--url https://<YOUR_URL_HERE>.appspot.com/api/albums \
--header 'authorization: Bearer '$JWT
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request GET \
--url https://<YOUR_URL_HERE>.appspot.com/api/albums/5a12c7b384a89046c0624bf4 \
--header 'authorization: Bearer '$JWT
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request POST \
--url https://<YOUR_URL_HERE>.appspot.com/api/tracks \
--header 'authorization: Bearer '$JWT \
--header 'content-type: application/json' \
--data '{"artists":[{"name":"Michael Jackson"}],"albums":[{"name":"Thriller"}],"duration":90,"image":"billiejean.png","name":"Beat It"}'
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request GET \
--url https://<YOUR_URL_HERE>.appspot.com/api/tracks \
--header 'authorization: Bearer '$JWT
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request GET \
--url https://<YOUR_URL_HERE>.appspot.com/api/tracks/5a12c7b384a89046c0624bf6 \
--header 'authorization: Bearer '$JWT
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request POST \
--url https://<YOUR_URL_HERE>.appspot.com/api/artists \
--header 'content-type: application/json' \
--header 'authorization: Bearer '$JWT \
--data '{"name":"Bob Marley","popularity":90,"genres":[{"name":"Pop"}],"image":"bm.jpg"}'
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request GET \
--url https://<YOUR_URL_HERE>.appspot.com/api/artists \
--header 'authorization: Bearer '$JWT
CLIENT_ID="<YOUR-CLIENT-ID-HERE>";
CLIENT_SECRET="YOUR-CLIENT-SECRET-HERE";
JWT=$(curl --request POST \
--url https://<YOUR-AUTH0-DOMAIN>.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'","audience":"<YOUR-AUDIENCE-ATTRIBUTE-HERE>","grant_type":"client_credentials"}' | jq .access_token -r);
curl --request GET \
--url https://<YOUR_URL_HERE>.appspot.com/api/artists/5a12c7b384a89046c0624bf4 \
--header 'authorization: Bearer '$JWT
All requests must be prefixed with <YOUR_URL_HERE>.appspot.com/api/
EndPoint | Functionality |
---|---|
POST /albums/ | Creates a new album instance. |
GET /albums/ | Returns all albums. |
GET /albums/<id> |
Returns the specified album id. |
PUT /albums/<id> |
Update album attributes. |
DELETE /albums/<id> |
Delete album. |
EndPoint | Functionality |
---|---|
POST /tracks/ | Creates a new track instance. |
GET /tracks/ | Returns all tracks. |
GET /tracks/<id> |
Returns the specified track id |
PUT /tracks/<id> |
Update track attributes. |
DELETE /tracks/<id> |
Delete track. |
EndPoint | Functionality |
---|---|
POST /artists/ | Creates a new artist instance. |
GET /artists/ | Returns all artists. |
GET /artists/<id> |
Returns the specified artist id. |
PUT /artists/<id> |
Update artist attributes. |
DELETE /artists/<id> |
Delete artist. |
-
Clone this repo:
git clone https://github.com/philipszdavido/spotify-app.git
-
Move into the
spotify-app
directory from the terminal:cd spotify-app
-
Install depedencies using
npm
oryarn
:npm install
or
yarn install
-
Run the sample with
npm
oryarn
:npm start
or
yarn start
-
Visit the application at
http://localhost:3000
.
-
Use the Google Cloud Console to create a Google Cloud Platform project.
-
Enable billing for your project.
-
Use the Cloud SDK to deploy your app.
gcloud app deploy
Note: If there is a
yarn.lock
file thenyarn install
will be used during deployment. Delete theyarn.lock
file to fall back tonpm install
. -
View your deployed application at
https://YOUR_PROJECT_ID.appspot.com
orgcloud app browse
.