Use Indaba as data provider (API)
Closed this issue · 2 comments
Description
We are completely replacing the use of a custom API we previously built for this project - Aquarium - with a solution provided by a 3rd party - Indaba. In order to get started, we'll create a module designed to wrap the Indaba API and expose the endpoints it provides to the rest of the application.
This issue does not deal with the refactoring of the code itself to actually use the Indaba API: that comes in #62
Usage notes for the API
- POST data must be as JSON
- GET requests always need an
access_token
parameter with the access token for the API. (?access_token={PORTED_API_TOKEN}
)
Tasks
- Bootstrap a new module for our API wrapper. You'll create a connection to the API and add functions/methods for access to the API endpoints, including passing params to the endpoints that accept them.
- See the API docs here, but note there are definitely bugs in those docs :)
- Do not use jQuery! Use the Fetch API which modern browsers implement. Use a fetch polyfill for the browsers that do not. Use the fetch implementation for node for your unit tests. In the past, we've used isomorphic-fetch for code that runs on both server and client, but you probably do not need that. Here is an example of using fetch in a real codebase
- All variables for configuration must be kept out of the codebase. This is problematic due to this site being hosted on GitHub pages. We can maybe change that to serve it in a Node shell, and thereby provide environment variables, or possibly another solution.... Just keep it in mind now and do not commit credentials to the codebase.
- Variables for API access are:
PORTED_API_BASE
PORTED_API_TOKEN
- Note: above we are only working with a token. The API has a login method, in order to get a token. We are just using this to generate a token with TTL of one year - I do not want to handle login, token expiry and so on in the code base - we'll just update our token manually once a year.
- Variables for API access are:
- Write a set of simple tests: call each endpoint, and assert the results are correct
@dumyan note here that because the tests only need to run in Node, you can export the environment variables in your shell to run locally, and, you can write the environment variables in an encrypted fashion to the travis file for the CI, example.
Here are the docs for the filter
method on collection endpoints: https://docs.strongloop.com/display/public/LB/Where+filter#Wherefilter-RESTAPI