- Notifications
You must be signed in to change notification settings - Fork23
A simple Koajs 2 Application REST Skeleton
License
ria-com/node-koajs-rest-skeleton
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A simpleKoajs 2.15.2 Application REST SkeletonThis version based onkoa 2.15.2.
Checkout node-koajs-rest-skeleton:
$ git clone https://github.com/ria-com/node-koajs-rest-skeleton
Make your own new project:
$ mv node-koajs-rest-skeleton my_new_project$cd my_new_project$ rm -rf .gitEdit package.json:
$ vi package.json
Edit config/ files:*
$ vi config/default.js
Install modules
$ npm install
Start app:
$ node ./index.js
Make your own Spec-files for testing and start test
In this skeleton for automatic testing was usedjasmine-nodie &Frisby (REST API testing framework).I wrote several tests that you can use as examples.
All tests should be placed in the ./spec folder. The name of each test file must end with *Spec.js
To run the tests, use
$cd my_new_project$ npmtest
Manual testing your REST service:
You can also manual check the serviceability of your service with bash andcurl
$ curl -XGET"http://localhost:8081/users/1"$ curl -XGET"http://localhost:8081/users"$ curl -XPOST"http://localhost:8081/users" -d'{"name":"New record 1"}' -H'Content-Type: application/json'
$ curl -XPUT"http://localhost:8081/users/3" -d'{"name":"New record 3"}' -H'Content-Type: application/json'
$ curl -XDELETE"http://localhost:8081/users/3"Usage: /usr/bin/node ./console.js --section [string] [--action [string]] [--opt [object]]Options: --opt, --options example --opt.app=mobile --opt.s=1 [default: {}] --section [required] --action [default:"index"]
For example
$ ./console.js --section=default --opt.hello=worldHello world defaultController& index action with options: {"hello":"world"}
Usage: NODE_WORKER_NAME=[worker_name] NODE_QUEUE_NAME=[queue_name] /usr/bin/node --harmony ./worker.js
For example
$ NODE_WORKER_NAME=example NODE_QUEUE_NAME=example /usr/bin/node --harmony ./worker.js
Several new features have been added that can be used in conjunction with kubernetes
Auto shutdown. Set the environment variableNODE_LIFE_TIME to specifythe time at which the service will suspend its work, for exsmple:NODE_LIFE_TIME=24h или NODE_LIFE_TIME=30m
If the variable is not set, then "Auto shutdown" is disabled
Redy state. Your app can tell the kubernetes system that itis temporarily not ready to accept new requests. How to do this isdescribed in the example below
const{setReady}=require('../controllers/kubernetesController');// ...// setReady(false) // to temporary disable new requests// ...// setReady(true) // to restore accept new requests
This should be configured in the config of kubernetes pod,the address on which poll is created:/redyz
Health state. Your app can tell the kubernetes system that itis temporarry broken. How to do this is described in the example below
const{setHealth}=require('../controllers/kubernetesController');// ...// setHealth(false) // to tell kubernetes: "app is broken"// ...// setHealth(true) // to tell kubernetes: "app is live"
This should be configured in the config of kubernetes pod,the address on which poll is created:/healthz
In order to avoid cluttering the minimal code of our REST-service, additionalfunctionality will be available when running the app viaindex.kubernetes.js:
$ node ./index.kubernetes.js
- v3.5 - Joi validator was added to check PUT & POST input data (thanks toRoman Yakovenko)
- v3.4 - Fix Dockerfile add /version route to kubernetes version
- v3.3 - Some kubernetes features added
- v3.2 - Updated dependencies for Koa 2.5, fix api tests, remove .babelrc
About
A simple Koajs 2 Application REST Skeleton
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.