Skip to content

Latest commit

 

History

History
100 lines (70 loc) · 2.44 KB

README.md

File metadata and controls

100 lines (70 loc) · 2.44 KB

Micromaterials API

Note: this is no longer in production, and exists only as a module for providing an endpoint for micromaterials to consume

Such Totes!

A REST-ful API For Words & Stuff

Read Adam's blog post here.

Setup

$ virtualenv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt

Running The Application

$ python wsgi.py

Running The Tests

Unit Tests

$ nosetests

Functional Tests

Note: these tests require a running MongoDB instance.

$ behave

The MongoDB instance defaults one running on localhost but you can change this in the settings.yml file.

$ MONGO_URL: '<insert the URL of your MongoDB instance here>'

Layout

  • krump :: the application source code.
  • test :: unit tests for the above source code.
  • cukes :: BDD tests for the application using Behave.

Serving Sentences

This next bit assumes that the DB is populated and the application is running.

To get sentences with a specific feature:

http://<SERVER_IP_ADDRESS:PORT>/api/sentence/<FEATURE>

Currently only JSON responses are supported: clients must supply an ACCEPT header value of application/json.

If there are no sentences with the desired feature in the underlying DB, then a 204 NO CONTENT response will be returned.

FEATURE might be apostrophe -- to get sentences with apostrophes -- or one of the features listed below.

  • simple_past
  • non_third_person_singular_simple_present
  • third_person_singular_simple_present
  • present_participle
  • past_participle
  • article
  • singular_noun
  • plural_noun
  • wh_determiner
  • comparative_adjective
  • superlative_adjective
curl -XGET -H 'Accept: application/json' http://localhost:9000/api/sentence/apostrophe

To get sentences with a specific word (if present in the database):

http://<SERVER_IP_ADDRESS:PORT>/api/sentence/word/<WORD>

The API also supports three query parameters:

  • count : the number of sentences to be returned. (Default 10.)

  • max-words : the maximum number of words in sentences returned. (Default 100.)

  • skip : allows paging and returns the next (skip * count) sentences in the response.