From 5fd10f999d9a0388a23b643242c27309c636252e Mon Sep 17 00:00:00 2001 From: Erika Pauwels Date: Sat, 8 Apr 2017 21:35:22 +0200 Subject: [PATCH] Update README.md --- README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d0248be..c7e2845 100644 --- a/README.md +++ b/README.md @@ -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 @@ -9,7 +9,7 @@ Create a new folder. Add the following Dockerfile: FROM semtech/mu-javascript-template MAINTAINER Aad Versteden -Create your microservice: +Create your microservice in `app.js`: import { app, query } from 'mu'; @@ -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. @@ -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 \