This example illustrates the use of Carbon.io to implement a public API for managing personal contacts. This API also handles user management, and allows for new users to register via the API, and then use the API to manage their contacts separate from other users' contacts.
We encourage you to clone the git repository so you can play around with the code.
$ git clone [email protected]:carbon-io-examples/contacts-service-advanced.git
$ cd contacts-service-advanced
$ npm install
This example expects a running MongoDB database. The code will honor a DB_URI
environment variable. The default URI is
mongodb://localhost:27017/contacts
.
To set the environment variable to point the app at a database different from the default (on Mac):
$ export DB_URI=mongodb://localhost:27017/mydb
To run the service:
$ node lib/ContactService
For cmdline help:
$ node lib/ContactService -h
You can interact with the service via HTTP. Here is an example using curl to create a new user:
$ curl localhost:9900/users -H "Content-Type: application/json" -d '{"email":"[email protected]", "password":"foobar"}'
This example comes with a simple unit test written in Carbon.io's test framework called TestTube. It is located in the test
directory.
$ node test/ContactServiceTest
or
$ npm test
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/ContactService gen-static-docs --flavor aglio --out docs/index.html