intermine/im-runnable

Name: im-runnable

Owner: InterMine

Description: Learn you some InterMine Web Services for good

Created: 2014-08-17 01:02:16.0

Updated: 2014-07-29 19:32:36.0

Pushed: 2014-02-28 12:29:20.0

Homepage:

Size: 1116

Language: null

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

InterMine Runnable Built with Grunt

Learn you some InterMine Web Services for good.

image

Quickstart

Install Docker and test all is well:

cker run ubuntu /bin/echo hello world

Create an intermine image based on a Dockerfile:

cker build -t intermine server/

Install service dependencies:

m install

Start the service:

do PORT=5000 node index.js
Commands
Update image

While your container is still running, get its id and save it as an image:

cker commit <id> intermine
cker images

Now we have an image saved under intermine. You can now exit from the container.

You can also edit the Dockerfile in server/ and rerun the abovementioned command to update the image.

Languages/environments

The following command in server/run.sh is being run for each new job:

ho "$1" | sudo docker run -i intermine /bin/bash -c "$2"

The first argument is a script source, the second is one command out of server/config.coffee e.g.:

t > script.js; node script.js
Production
m install pm2 -g
RT=80 pm2 start index.js
API

You can post some code to get a job id back:

sr/bin/env coffee
ify = require 'restify'

nt = restify.createJsonClient
'url': 'http://0.0.0.0:5000'

nt.post '/api/v1/jobs.json',
'lang': 'javascript'
'src':  'console.log(3*6)'
rr, req, res, body) ->
throw err if err
Design
  1. Use plural nouns, not verbs.
  2. Provide a message when handling errors.
  3. Only 3 levels of depth when showing associations, e.g.: /owners/123/dogs.
  4. All responses contain a responseCode.
  5. Be able to override status codes and always return 200 in the header but not in the body; use ?suppress_response_codes=true.
  6. Codes:
    • 200 OK
    • 201 Created: when submitting new items
    • 400 Bad Request: it is the client's fault, like params not provided
    • 401 Not Authorized: you can access this page, but your token is no good
    • 404 Not Found
    • 500 Internal Server Error: client is fine, we are at fault
  7. Do versioning, but do not change versions often.
  8. Never respond with a JSON Array, always an Object.
  9. Allow people to specify format in a suffix .json, but default to JSON.
  10. Specify which fields to return using query param ?fields=name,color.
  11. When returning a listing of many things, return only a partial and assume that ?limit=10&offset=0. Metadata related to total count, limit & offset should be returned under metadata key in response.
  12. Search is done by appending ?q=wulfie to the resource or /search?q=wulfie for a global one.
  13. When returning timestamps use toJSON() so we can nicely debug in the browser.
  14. Key names in responses (JSON) need to follow the same pattern as those in URLs so created_at.
  15. When creating objects, it should return them.
  16. When returning an object or an array, return it under data key.
  17. Support trailing slashes in urls.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.