1.0.0 • Published 6 years ago

koop-provider-asap v1.0.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
6 years ago

Build Status Greenkeeper badge

Koop Sample Provider

This is a sample that demonstrates how to build a Koop Provider. You can clone this project, and use it to start a new provider. This sample can run a local server, deploy to AWS Lambda or Docker for testing and operations. Once the provider is published to NPM, then it can be used with other Koop providers and outputs in a larger project.

The data source in this example is the TriMet Bus API. You can see this provider in action here.

Full documentation is provided here.

Getting started

  1. Open index.js and change provider.name to a unique name
  2. Open config/default.json with any configurable parameters
  3. Open model.js and implement getData to call your provider and return GeoJSON
  4. Install dependencies npm install
  5. Run a local server npm start
  6. Add tests to test/

Koop provider file structure

FileDescription
index.jsMandatoryConfigures provider for usage by Koop
model.jsMandatoryTranslates remote API to GeoJSON
routes.jsOptionalSpecifies additional routes to be handled by this provider
controller.jsOptionalHandles additional routes specified in routes.js
server.jsOptionalReference implementation for the provider
test/model-test.jsOptionaltests the getData function on the model
test/fixtures/input.jsonOptionala sample of the raw input from the 3rd party API
config/default.jsonOptionalused for advanced configuration, usually API keys.

Test it out

Run server:

  • npm install
  • npm start

Example API Query:

  • curl localhost:8080/sample/FeatureServer/0/query?returnCountOnly=true

Tests:

  • npm test

Development output callstack logs

During development you can output error callstack with

  • NODE_ENV=test npm start

Deploy to AWS Lambda

Koop providers can be quickly deployed and scaled with AWS Lambda. To first create the service:

  • npm run lambda-create

To deploy code updates

  • npm run lambda-update

AWS Lambda configuration

By default, AWS Lambda has a 3 second timeout and only 128MB memory. If your Koop provider uses a slower service, then you should change the AWS Lambda timeout to a higher time limit (e.g. 60 seconds) as well as add more memory (e.g. 512MB).

With Docker

  • docker build -t koop-provider-sample .
  • docker run -it -p 8080:8080 koop-provider-sample

Publish to npm

  • run npm init and update the fields
    • Choose a name like koop-provider-foo
  • run npm publish