Example: Hello-world Service
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Hello Service

Build Status Carbon Version

This example illustrates the use of to implement the simplest possible RESTful web service.

The code defining the service is located in lib/HelloService.js and uses a simple Endpoint object to implement an HTTP GET at the path /hello:

__(function() {
  module.exports = o({
    _type: carbon.carbond.Service,
    port: 8888,
    endpoints : {
      hello: o({
        _type: carbon.carbond.Endpoint,
        get: function(req, res) {
          return { msg: "Hello world!" }

Installing the service

We encourage you to clone the git repository so you can play around with the code.

$ git clone -b carbon-0.7
$ cd example__hello-world-service
$ npm install

Running the service

To run the service:

$ node lib/HelloService

For cmdline help:

$ node lib/HelloService -h

To access the /hello endpoint:

$ curl localhost:8888/hello
{ msg: "Hello world!" }

Running the unit tests

This example comes with a simple unit test written in's test framework called TestTube. It is located in the test directory.

$ node test/HelloServiceTest


$ npm test

Generating API documentation (aglio flavor)

To generate documentation using aglio, install it as a devDependency:

$ npm install -D --no-optional aglio

Using --no-optional speeds up aglio's install time significantly. Then generate the docs using this command:

$ node lib/HelloService gen-static-docs --flavor aglio --out docs/index.html