Versions Compared

Key

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

Introduction

...

Code Block
languagebash
titleRunning the service
linenumberstrue
# go to correct directoryexamples/hello_world and start the service
cd /opt/soajs.examples/nodehello_modules/soajs.examples/example01/world/
 
# 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.jsENV=EXAMPLE
export SOAJS_SRVPORT=4021
export SOAJS_ENVDEPLOY_MANUAL=test1
export SOAJS_REGISTRY_SRVIPAPI=127.0.0.1:21000
 
 
# start service
node .

Each running service listens on two ports: The data port and the maintenance port.

The service in this example runs on the local machine, and listens on port 40104021.

The second port is the maintenance port. The convention we use at SOAJS for maintenance ports is maintenance port = data port + 1000 therefore, the maintenance port is 5010 for this service.

...

Code Block
languagebash
titleHeartbeat
linenumberstrue
curl -X GET "http://127.0.0.1:50105021/heartbeat"

The response below indicates that the service is running without any errors.

...

Code Block
languagebash
titleTestGet request: Missing Last Name
curl -X GET "http://127.0.0.1:40104021/testGet?firstName=John"

As expected, the API returned an error response. Since "lastName" is a required field and is missing in the querystring, the IMFV stopped the request returned an error response.

...

Code Block
languagebash
titleTestGet request: Success
linenumberstrue
curl -X GET "http://127.0.0.1:40104021/testGet?firstName=John&lastName=Smith" 

...

Code Block
languagejs
titleTestGet Reponse: Success
linenumberstrue
{"result": true,"data": {"firstName": "John","lastName": "Smith"}}

"testPost" API: Success

This API is exactly like testGet but uses the "post" method.

Code Block
languagebash
titleTestPost request: Sucess
linenumberstrue
curl -X POST -H "Content-type:application/json" -H "Accept:application/json" "http://127.0.0.1:4010/testPost" -d '{"firstName":"John","lastName":"Smith","email":"john@smith.com"}'

...

Code Block
languagebash
titleTestPost request: Failure
linenumberstrue
curl -X POST -H "Content-type:application/json" -H "Accept:application/json" "http://127.0.0.1:40104021/testPost" -d '{"firstName":"Johnx","lastName":"Smith"}'

...

Code Block
languagebash
titleTestPut request: Success
linenumberstrue
curl -X PUT -H "Content-type:application/json" -H "Accept:application/json" "http://127.0.0.1:40104021/testPut" -d '{"firstName":"John","lastName":"Smith"}'

...

Code Block
languagebash
titleTestDel request: Success
linenumberstrue
curl -X DELETE "http://127.0.0.1:40104021/testDel?firstName=John&lastName=Smith"

...

Code Block
languagebash
titleBuildName request: Success
linenumberstrue
curl -X GET "http://127.0.0.1:40104021/buildName?firstName=James&lastName=Smith"

...

"buildName" API: Success (No FirstName Parameter)

In this test, the "firstName" parameter is not supplied. However, since the API is configured to fallback to a default value, no error response is generated. Rather, a response containing the default "firstName", in addition to the "lastName" supplied by the request, was generated instead.

Code Block
languagebash
titleBuildName request: Success
linenumberstrue
curl -X GET "http://127.0.0.1:40104021/buildName?lastName=Smith"


Code Block
languagejs
titleBuildName request: success
linenumberstrue
{"result": true,"data": {"fullName": "John Smith"}}