This repository contains the code for generating the mock API the ccsp-experiment prototype depends on.
The prototype runs on github pages but requires this API. It's currently running on my personal Heroku account at https://ccsp-api.herokuapp.com/ The API contains mock data generated with faker.js, so there are no privacy issues.
The following instructions assume you have node.js
and npm
installed on your system.
The API consists of an api.json
file served with json-server
to run it on localhost:3000
, type
npm run-script serve-api
api.json
is generated by the make-api.js
file, to regenerate type
npm run-script make-api
to regenerate and build in one step (live life to the fullest), you can execute
npm run-script make-api
- At the time of writing the API url is hardcoded to an Heroku app in ccsp-experiment.
I plan to let ccsp-experiment app look for the API at
localhost:3000
, when the app itself is served from localhost in the future.
The output in the terminal will show the available API resources (i.e. employees, spouses, children, applications, awards). For more information on what the API server can do, consult the json-server README.md file. Spoiler alert: pagination, filtering, search, routing, slicing, etc. are available, as are the GET, PUT, POST, PATCH, DELETE HTTP methods.
Operators can be tacked on as query parameters. E.g. This call to employees
will return the third page (collection sliced by 10 items/page) of the collection with the "id referenced" children, spouse, and applications items embedded in the JSON.
http://localhost:3000/employees?_embed=children&_embed=applications&_embed=spouses&_page=3
-
Create an account on
https://heroku.com -
Install the Heroku CLI on your computer:
https://devcenter.heroku.com/articles/heroku-cli -
Connect the Heroku CLI to your account by writing the following command in your terminal and follow the instructions on the command line:
heroku login
- Then create a remote Heroku project
heroku create
This will create a project on Heroku with a random name. If you want to name your app you have to supply a name:
heroku create app-name
- Add the heroku remote to your clone of this repository (substitute
app-name
with your choice)
git remote add heroku https://git.heroku.com/app-name.git
I added this repository as well (assuming you're using SSH instead of HTTPS)
git remote add origin [email protected]:jandw/ccsp-api.git
- Check your remotes are properly set up
git remote -v
should output this in the terminal
origin [email protected]:jandw/ccsp-api.git (fetch)
origin [email protected]:jandw/ccsp-api.git (push)
heroku https://git.heroku.com/jans-test.git (fetch)
herolu https://git.heroku.com/jans-test.git (push)
- If needed, build the API and commit it
npm run-script make-api && git add -A && git commit -m "API build"
- Push the API to heroku
git push -u heroku master
This also sets up tracking, so in the future, you should be able to just use git push
to deploy. Next, push the changes to github.mit.edu/jandw/ccsp-api
git push origin master
You should see the push, followed by terminal output regarding the heroku build of the api
- Visit the newly created app by opening it via heroku:
heroku open
- If something went wrong, check the logs:
heroku logs --tail
- To delete the herokuapp
heroku apps:destroy app-name