Skip to content

jstoiko/raml-javascript-client

Repository files navigation

Clone this repo with the recursive option git clone --recursive.

Install and run the backend API server

Prerequisites: Python and Virtualenv. Elasticsearch and PostgreSQL must be running with default settings.

$ cd ramses-tutorial/pizza_factory
$ virtualenv venv && . venv/bin/activate
(venv)$ pip install nefertari-sqla -r requirements.txt
(venv)$ pserve local.ini

In another terminal session, attach to the same virtual environment as the API server and post some seed data.

$ cd ramses-tutorial/pizza_factory
$ . venv/bin/activate
(venv)$ nefertari.post2api -f seeds/toppings.json -u http://localhost:6543/api/toppings
(venv)$ nefertari.post2api -f seeds/cheeses.json -u http://localhost:6543/api/cheeses
(venv)$ nefertari.post2api -f seeds/sauces.json -u http://localhost:6543/api/sauces
(venv)$ nefertari.post2api -f seeds/crusts.json -u http://localhost:6543/api/crusts

Generate the API documentation

$ npm i -g raml2html
$ raml2html ramses-tutorial/pizza_factory/api.raml > api-doc.html
$ open api-doc.html

Generate and try the client library in node

Then go back to the root of this project and get cracking.

$ cd ../../
$ npm i -g raml-client-generator
$ raml-to-client ramses-tutorial/pizza_factory/api.raml -o pizza-factory-api -l javascript
$ npm install pizza-factory-api

You can see complete details of how to use the client in pizza-factory-api/README.md. Now you will have a client library that already knows how to use the Pizza Factory API.

$ node
> var PizzaFactoryApi = require('pizza-factory-api');
> var client = new PizzaFactoryApi();
> var resource = client.resources.toppings;
> resource.get().then(function (res) { console.log(res.body) });

Install and run the frontend app

Prerequisites: Npm (ships with Node.js) and Gulp (npm install -g gulp)

$ npm install
$ gulp

About

Example of RAML generated JavaScript client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published