Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

...

In the Basic Service example, we learned to perform a heartbeat check on a service to monitor its health.

...

Every request made to the service is first validated by the SOAJS oAuth Service before being forwarded to the service.

Code Walkthrough

...

This page shows you how to interact with example02 service after you install it and run it.

The code walkthrough is located in a sub page and explained in depth. Click here to read the explanation.

Service Exploration

...

Run the Service

Code Block
languagebash
linenumberstrue
# 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 .

...

Code Block
{"result":true,"ts":1425131238011,"service": {"service":"example02","type":"rest","route":"/heartbeat"}}

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
{result: false, errors: {codes: [ 400 ],details: [ { code: 400, message: "The access token was not found"}]}}

Login to oAuth

The user must login to oAuth and get an access token.

...

Code Block
{"token_type":"bearer","access_token":"30f3a13fcdb60cde1cdf576634cbb7777df31177","expires_in":3600,"refresh_token":"6ea967dfe6c005d86b6fb0b0331ed52b89a1cee7"}

TestGet with a valid oAuth access token

What follows is a new request to the testGet API. However, the request in this example contains the valid access_token obtained above. As can be seen in the code block below, the access_token is appended to the request.

...