Skip to content

ScottDowne/MakeAPI

 
 

Repository files navigation

MakeAPI

Running the Server

Prerequisites

Dependencies

Execute npm install in the application directory:

Running in Development mode

Configuration for Node w/ Habitat

Copy and edit your .env file. -- This should never be committed to the repo.

cp env.sample .env

Running the Services

Before you start your Node.js server, you'll need to run MongoDB and ElasticSearch

Running the Node Server

Assuming MongoDB and ElasticSearch are running at the specified places in your .env file simply running node server.js from the root should start the server.

By default the server will run at http://localhost:5000. You can change this by adding PORT= to your .env file.

API Keys

The Create, Update and Delete Routes are protected using Hawk.

All applications that wish to make authenticated calls must be issued a pair of keys to sign all requests. Keys are optional for search requests.

The generation of keys can be done using the generateKeys script.

The script is called with two arguments: an email address to associate with the keys and a integer indicating the number of pairs to be generated. Generated keys are added to the database and then outputted to the console.

There is also a tool in the Admin Make Editor that generates keys. It can be reached by visiting http://localhost:5000/admin (change the hostname & port appropriately)

For convenience of development and testing, the USE_DEV_KEY_LOOKUP variable can be set to true in the environment file. This flag will use a DEVELOPMENT ONLY strategy when verifying keys.

When development key mode is enabled, clients can sign their requests by passing hawk `"00000000-0000-0000-000000000000" as their public and private key. Any other key combination will fail to authenticate.

DO NOT USE DEV KEYS OUTSIDE OF A DEVELOPMENT ENVIRONMENT!

New Relic

To enable New Relic, set the NEW_RELIC_ENABLED environment variable and add a config file, or set the relevant environment variables.

For more information on configuring New Relic, see: https://github.com/newrelic/node-newrelic/#configuring-the-agent

Deploying to Heroku

If you don't have Heroku Toolbelt get it here https://toolbelt.heroku.com/.

You will need an account with heroku. If you don't have one, sign up for one at http://heroku.com.

  1. Ensure you are logged in first by running heroku login
  2. Go to the root of the repo.
  3. heroku create
  4. Add the necessary plugins using heroku addons:add <plugin name>. Supported MongoDB plugins are: MongoHQ and MongoLab. Supported Elastic Search plugins are: FoundElasticSearch and Bonsai. Installing a plugin should automatically set up the required environment variables.
  5. You should be ready to push up to heroku! git push heroku featureBranchName:master. If all goes well, your app should deploy. You can see logs by running heroku logs and you can open the MakeAPI in a browser by running heroku open.

Testing the API

The QueryBuilder's mocha test suite can be run by executing npm test. NOTE: you must have installed mocha, npm install -g mocha

API:

HTTP Method Path Action Notes Auth Required
POST /api/make Create Make If post data contains a valid Make, it creates one and returns it with the _id. Post Data should be a JSON object specifying the id of the authenticated webmaker creating the Make
{ "maker": "username", make: { ... } }
Yes
PUT /api/make/:id Update a Make The Make must already exist. This is an implementation of optimistic locking. Post Data should be a JSON object specifying the id of the authenticated webmaker updating the Make and a flag indicating if the user has admin priveliges.
{ "maker": "username", make: { ... } }
Yes
DELETE /api/make/:id Deletes a Make The effect is that of a delete operation, though the Make is actually only marked as deleted using the deletedAt timestamp. Post Data should be a JSON object specifying the id of the authenticated webmaker deleting the Make and a flag indicating if the user has admin priveliges.
{ "maker": "username" }
Yes
GET /api/makes/search Find makes by search criteria

Searches for makes using elasticsearch. The Query String of your request must be stringified and escaped JSON, and must use elastic search's Query DSL. e.g. /api/makes/search/?s=URLENCODEDSEARCHSTRING

No

Consuming the API

The makeapi-client should be used to facilitate interaction with the API. Documentation can be found here

The Make API Does not sanitize Data it receives or outputs, so it is up to consumer applications to sanitize data appropriately.

Deleting all fake data

Clear elastic search:

curl -XDELETE "http://localhost:9200"

Find your mongo files and clear them. For example, if your makeapi.1, etc. are in /data/db/, run:

rm /data/db/makeapi.*

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 96.8%
  • CSS 3.2%