Versions Compared

Key

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

Introduction

...

Code Block
languagebash
titleRunning the service
linenumberstrue
# go to examples/hello_worldexample01 and start the service
cd soajs.examples/hello_worldexample01/
 
# start the soajs example environment
sudo soajs services start --env=example
 
# export necessary environment variables to create local awareness
export SOAJS_ENV=EXAMPLE
export SOAJS_SRVPORT=4021
export SOAJS_DEPLOY_MANUAL=1
export SOAJS_REGISTRY_API=127.0.0.1:21000
 
 
# start service
node .

...

The first API to test is the "TestGet". In this scenario, the request is sent with only the "firstName" input. The request does not contain the second mandatory input: "lastName". So we expect the response to return with an error.

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

...

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
languagebashjs
titleTestPost request: Sucess
linenumberstrue
curl -X POST -H "Content-type:application/json" -H "Accept:application/json" "http://127.0.0.1:40104021/testPost" -d '{"firstName":"John","lastName":"Smith","email":"john@smith.com"}'

...

This request fails because of the invalid firstName "johnx" (Instead of "john"). This restriction is specified in the service itself.

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

...

SOAJS also provides supports the PUT method:

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

...

SOAJS also provides supports the DEL protocol:

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

...

In this first request, both "firstName" and a "lastName" parameters are supplied.

Code Block
languagebashjs
titleBuildName request: Success
linenumberstrue
curl -X GET "http://127.0.0.1:4021/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
languagebashjs
titleBuildName request: Success
linenumberstrue
curl -X GET "http://127.0.0.1:4021/buildName?lastName=Smith"


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