Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
erikap committed Apr 8, 2017
1 parent 7095973 commit 5fd10f9
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mu-javascript-template
# Mu Javascript template

Template for writing mu.semte.ch services in JavaScript
Template for writing mu.semte.ch services in JavaScript using [Express 4](https://expressjs.com/)

## Getting started

Expand All @@ -9,7 +9,7 @@ Create a new folder. Add the following Dockerfile:
FROM semtech/mu-javascript-template
MAINTAINER Aad Versteden <[email protected]>

Create your microservice:
Create your microservice in `app.js`:

import { app, query } from 'mu';

Expand All @@ -35,18 +35,22 @@ Create your microservice:
res.send( "Oops something went wrong: " + JSON.stringify( err ) );
});
} );

Check [Express' Getting Started guide](https://expressjs.com/en/starter/basic-routing.html) to learn how to build a REST API in Express.

## Requirements

- **database link**: You need a link to the `database` which exposes a sparql endpoint on `http://database:8890/sparql`. In line with other microservices.
- **database link**: You need a link to the `database` which exposes a SPARQL endpoint on `http://database:8890/sparql`. In line with other microservices.

## Imports

The following importable variables are available:

- `app`: The application on which routes can be added
- `app`: The [Express application](https://expressjs.com/en/guide/routing.html) on which routes can be added
- `query(query) => Promise`: Function for sending queries to the triplestore
- `update(query) => Promise`: Function for sending updates to the triplestore
- `uuid()` => string: Generates a random UUID
- `sparql`: [Template tag](https://www.npmjs.com/package/sparql-client-2#using-the-sparql-template-tag) to create queries with interpolated values

You can either import specific attributes from the mu library, or import the whole mu object.

Expand All @@ -66,11 +70,15 @@ An example of importing the whole library:
res.send('Hello using full import');
} );

## Dependencies

You can install additional dependencies by including a `package.json` file next to your `app.js`. It works as you would expect: just define the packages in the `dependencies` section of the `package.json`. They will be installed automatically at build time.

## Developing with the template

When developing, you can use the template image, mount the volume with your sources on `/app` and add a link to the database.
When developing, you can use the template image, mount the volume with your sources on `/app` and add a link to the database. The service will live-reload on changes. You'll need to restart the container when you define additional dependencies in your `package.json`.

dr run --link virtuoso:database \
docker run --link virtuoso:database \
-v `pwd`:/app \
-p 8888:80 \
--name my-js-test \
Expand Down

0 comments on commit 5fd10f9

Please sign in to comment.