...
The code walkthrough is located in a sub page and explained in depth. Click here to read the explanation.
Service Exploration
...
To turn on the gateway in a development environment you just need to start the environment as follow
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# go to correct directory
cd /opt/soajs/node_modules/soajs.examples/example02/
# export necessary environment variables
export SOAJS_PROFILE=/opt/soajs/node_modules/soajs.utilities/data/getStarted/profile.js
export SOAJS_ENV=test
export SOAJS_SRVIP=127.0.0.1
# start service
node . |
Since this example makes use of the oAuth service, let's go ahead and turn that service on as well.
In a separate terminal window, enter the following:
Code Block | ||||
---|---|---|---|---|
| ||||
# go to directory and install oauth
cd /opt/soajs/node_modules/
npm install soajs.oauth
# go to oauth directory
cd /opt/soajs/node_modules/soajs.oauth
# export necessary environment variables
export SOAJS_PROFILE=/opt/soajs/node_modules/soajs.utilities/data/getStarted/profile.js
export SOAJS_ENV=test
export SOAJS_SRVIP=127.0.0.1
# start service
node . |
...
Code Block |
---|
curl -X GET "http://127.0.0.1:5002/heartbeat" |
The response below indicates that the oAuth service is running error free.
Code Block |
---|
{"result":true,"ts":1425131003103,"service": {"service":"oauth","type":"rest","route":"/heartbeat"}} |
Another heartbeat request is sent to the example02 service whose maintenance port is 5011.
Code Block |
---|
curl -X GET "http://127.0.0.1:5011/heartbeat" |
The response below indicates that the service is running without any errors.
Code Block |
---|
{"result":true,"ts":1425131238011,"service": {"service":"example02","type":"rest","route":"/heartbeat"}} |
sudo soajs services start --env=example |
Info | ||
---|---|---|
| ||
To verify if oauth is running you need to login to soajs console and
|
Using the Service APIs
In the Basic Service example, the "testGet" API was not designed to be secured with oAuth. In this example we added this security option to it.
...
Code Block | ||||
---|---|---|---|---|
| ||||
# go to controller directory examples/example02 and start the service cd soajs.examples/opt/soajs/node_modules/soajs.controllerexample02/ # start the soajs example environment sudo soajs services start --env=example # export necessary environment variables to create local awareness export SOAJS_PROFILE=/opt/soajs/node_modules/soajs.utilities/data/getStarted/profile.js ENV=EXAMPLE export SOAJS_SRVPORT=4022 export SOAJS_ENVDEPLOY_MANUAL=test1 export SOAJS_REGISTRY_SRVIPAPI=127.0.0.1:21000 # start service node . # hit the API curl -X GET "http://127.0.0.1:400020000/example02/buildName?firstName=John&lastName=Smith" |
...
Code Block |
---|
curl -X POST -H "Authorization: Basic MTBkMmNiNWZjMDRjZTUxZTA2MDAwMDAxOnNoaGggdGhpcyBpcyBhIHNlY3JldA==" -H "key:aa39b5490c4a4ed0e56d7ec1232a428f771e8bb83cfcee16de14f735d0f5da587d5968ec4f785e38570902fd24e0b522b46cb171872d1ea038e88328e7d973ff47d9392f72b2d49566209eb88eb60aed8534a965cf30072c39565bd8d72f68ac" "http://127.0.0.1:400020000/oauth/token" -d 'username=oauthuser&password=oauthpassword&grant_type=password' |
...
Code Block |
---|
curl -X GET "http://127.0.0.1:400020000/example02/buildName?firstName=John&lastName=Smith&access_token=30f3a13fcdb60cde1cdf576634cbb7777df31177" |
...