{"_id":"57241f832887bb0e00bb9da8","user":"5723ea8efda3c70e005b88e3","category":{"_id":"5723eaebeae5090e00ee61f2","version":"5723eaebeae5090e00ee61f1","project":"5723ead0fda3c70e005b88e5","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-04-29T23:14:24.983Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"parentDoc":null,"project":"5723ead0fda3c70e005b88e5","version":{"_id":"5723eaebeae5090e00ee61f1","__v":3,"project":"5723ead0fda3c70e005b88e5","createdAt":"2016-04-29T23:14:51.190Z","releaseDate":"2016-04-29T23:14:51.190Z","categories":["5723eaebeae5090e00ee61f2","5723f854110e570e00486c7a","572a28f6d10a200e00b1cb14"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.1.0","version":"0.1"},"__v":18,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-30T02:59:15.770Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"# Prerequisites\n\n* [Docker](https://docs.docker.com/engine/installation/) 1.11+ and [Docker Compose](https://docs.docker.com/compose/install/) 1.7+. On a Mac you can install [Docker Toolbox](https://docs.docker.com/toolbox/overview/) to get what you need.\n* Make\n* Linux or Mac (Windows should work too but it was never tested)\n\nIf you need to use docker-machine to run docker (eg on a Mac), you also need to install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) and then run these commands to [get started](https://docs.docker.com/machine/get-started/):\n\n```\n$ docker-machine create --driver virtualbox default\n$ eval `docker-machine env default`\n```\n\nYou will need to run the second command for every new terminal window.\n\n# Installation\n\n```bash\n$ git clone https://github.com/leveros/leveros\n$ cd leveros\n$ make\n$ sudo make install-cli\n$ make fastrun\n```\n\nThe commands above pull the necessary Docker images, install the `lever` CLI and run a Lever OS instance locally.\n\n# Your first Lever service\n\n```bash\n$ mkdir hello\n$ cd hello\n```\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"module.exports.sayHello = function (name, callback) {\\n    callback(null, \\\"Hello, \\\" + name + \\\"!\\\");\\n};\",\n      \"language\": \"javascript\",\n      \"name\": \"server.js\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"name\\\": \\\"helloService\\\",\\n    \\\"description\\\": \\\"A hello service.\\\",\\n    \\\"jsEntry\\\": \\\"server.js\\\"\\n}\",\n      \"language\": \"json\",\n      \"name\": \"lever.json\"\n    }\n  ]\n}\n[/block]\n### Deploy your service locally\n\n```bash\n$ lever deploy\n```\n\nThis takes the whole current directory, archives it and deploys it onto Lever in `dev.lever`, the default environment.\n\n### Invoke via CLI\n\n```bash\n$ lever invoke lever://dev.lever/helloService/sayHello '\"world\"'\n\n\"Hello, world!\"\n\n# Or even shorter (only for dev.lever)...\n$ lever invoke /helloService/sayHello '\"world\"'\n\n\"Hello, world!\"\n```\n\nRemember to use proper JSON for arguments. This includes the quotes for strings.\n\n### Invoke via HTTP POST request\n\n```bash\n# Without docker-machine\n$ curl -H \"Content-Type: application/json\" -X POST -d '[\"world\"]' \\\nhttp://127.0.0.1:8080/helloService/sayHello?forceenv=dev.lever\n\n\"Hello, world!\"\n\n# With docher-machine\n$ curl -H \"Content-Type: application/json\" -X POST -d '[\"world\"]' \\\nhttp://$(docker-machine ip default):8080/helloService/sayHello?forceenv=dev.lever\n\n\"Hello, world!\"\n```\n\nNotice the `forceenv` query param at the end of the command. This is a convenience feature that allows you to access Lever's HTTP API without having `dev.lever` assigned to the listening IP (and also configuring Lever to serve on port `80`).\n\n### Invoke from browser (via HTTP API)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$.ajax({\\n    'type': 'POST',\\n    'url': 'http://127.0.0.1:8080/helloService/sayHello?forceenv=dev.lever',\\n    'contentType': 'application/json',\\n    'data': JSON.stringify([\\\"world\\\"]),\\n    'dataType': 'json',\\n    'success': function (data) {\\n        console.log(data);  // Hello, world!\\n    },\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"browser.js\"\n    }\n  ]\n}\n[/block]\nNote that when using docker-machine, you need to replace `127.0.0.1` with the output of the command `docker-machine ip default`.\n\n### Invoke from Node\n\n```bash\n$ npm install leveros\n```\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var leveros = require('leveros');\\n\\nvar client = new leveros.Client();\\nclient.forceHost = process.env.LEVEROS_IP_PORT;\\nvar service = client.service('dev.lever', 'helloService');\\nservice.invoke('sayHello', \\\"world\\\", function (error, reply) {\\n    console.log(reply);  // Hello, world!\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"client.js\"\n    }\n  ]\n}\n[/block]\n```bash\n# Without docker-machine\n$ LEVEROS_IP_PORT=\"127.0.0.1:8080\" node client.js\n\n# With docher-machine\n$ LEVEROS_IP_PORT=\"$(docker-machine ip default):8080\" node client.js\n```\n\nSetting LEVEROS_IP_PORT is necessary so that you can invoke the `dev.lever` environment without adding an entry for it in `/etc/hosts` and setting the listen port to `80`.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"What's next?\"\n}\n[/block]\nNow that you have your first Lever service up and running, learn more about what you can do with Lever by taking a look at the [Concepts](doc:basic-concepts) page.\n\nLater, you might also want to check out the API reference pages. See links on left-hand side.","excerpt":"This page will help you install Lever OS and show you how to write your first Lever service!","slug":"quick-start","type":"basic","title":"Quick Start"}

Quick Start

This page will help you install Lever OS and show you how to write your first Lever service!

# Prerequisites * [Docker](https://docs.docker.com/engine/installation/) 1.11+ and [Docker Compose](https://docs.docker.com/compose/install/) 1.7+. On a Mac you can install [Docker Toolbox](https://docs.docker.com/toolbox/overview/) to get what you need. * Make * Linux or Mac (Windows should work too but it was never tested) If you need to use docker-machine to run docker (eg on a Mac), you also need to install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) and then run these commands to [get started](https://docs.docker.com/machine/get-started/): ``` $ docker-machine create --driver virtualbox default $ eval `docker-machine env default` ``` You will need to run the second command for every new terminal window. # Installation ```bash $ git clone https://github.com/leveros/leveros $ cd leveros $ make $ sudo make install-cli $ make fastrun ``` The commands above pull the necessary Docker images, install the `lever` CLI and run a Lever OS instance locally. # Your first Lever service ```bash $ mkdir hello $ cd hello ``` [block:code] { "codes": [ { "code": "module.exports.sayHello = function (name, callback) {\n callback(null, \"Hello, \" + name + \"!\");\n};", "language": "javascript", "name": "server.js" } ] } [/block] [block:code] { "codes": [ { "code": "{\n \"name\": \"helloService\",\n \"description\": \"A hello service.\",\n \"jsEntry\": \"server.js\"\n}", "language": "json", "name": "lever.json" } ] } [/block] ### Deploy your service locally ```bash $ lever deploy ``` This takes the whole current directory, archives it and deploys it onto Lever in `dev.lever`, the default environment. ### Invoke via CLI ```bash $ lever invoke lever://dev.lever/helloService/sayHello '"world"' "Hello, world!" # Or even shorter (only for dev.lever)... $ lever invoke /helloService/sayHello '"world"' "Hello, world!" ``` Remember to use proper JSON for arguments. This includes the quotes for strings. ### Invoke via HTTP POST request ```bash # Without docker-machine $ curl -H "Content-Type: application/json" -X POST -d '["world"]' \ http://127.0.0.1:8080/helloService/sayHello?forceenv=dev.lever "Hello, world!" # With docher-machine $ curl -H "Content-Type: application/json" -X POST -d '["world"]' \ http://$(docker-machine ip default):8080/helloService/sayHello?forceenv=dev.lever "Hello, world!" ``` Notice the `forceenv` query param at the end of the command. This is a convenience feature that allows you to access Lever's HTTP API without having `dev.lever` assigned to the listening IP (and also configuring Lever to serve on port `80`). ### Invoke from browser (via HTTP API) [block:code] { "codes": [ { "code": "$.ajax({\n 'type': 'POST',\n 'url': 'http://127.0.0.1:8080/helloService/sayHello?forceenv=dev.lever',\n 'contentType': 'application/json',\n 'data': JSON.stringify([\"world\"]),\n 'dataType': 'json',\n 'success': function (data) {\n console.log(data); // Hello, world!\n },\n});", "language": "javascript", "name": "browser.js" } ] } [/block] Note that when using docker-machine, you need to replace `127.0.0.1` with the output of the command `docker-machine ip default`. ### Invoke from Node ```bash $ npm install leveros ``` [block:code] { "codes": [ { "code": "var leveros = require('leveros');\n\nvar client = new leveros.Client();\nclient.forceHost = process.env.LEVEROS_IP_PORT;\nvar service = client.service('dev.lever', 'helloService');\nservice.invoke('sayHello', \"world\", function (error, reply) {\n console.log(reply); // Hello, world!\n});", "language": "javascript", "name": "client.js" } ] } [/block] ```bash # Without docker-machine $ LEVEROS_IP_PORT="127.0.0.1:8080" node client.js # With docher-machine $ LEVEROS_IP_PORT="$(docker-machine ip default):8080" node client.js ``` Setting LEVEROS_IP_PORT is necessary so that you can invoke the `dev.lever` environment without adding an entry for it in `/etc/hosts` and setting the listen port to `80`. [block:api-header] { "type": "basic", "title": "What's next?" } [/block] Now that you have your first Lever service up and running, learn more about what you can do with Lever by taking a look at the [Concepts](doc:basic-concepts) page. Later, you might also want to check out the API reference pages. See links on left-hand side.