Introduction
...
Service-Oriented Architecture built using JavaScript (SOAJS). Its services can be combined to provide the functionality of a large software application. Each Service is a collection of APIs easily managed by SOAJS framework and productized with multitenant capability. Its embedded self-awareness makes it easier to scale both horizontally and vertically letting all services running on the cloud to communicate effortless and form a massive reliable and scalable infrastructure to empower the communication between the product frontend and backend. SOAJS comes with tons of features, implementing SOAJS framework means getting a boost start of at least 50%.
In this page we will introduce a simple hello world example that demonstrates how easy it is to build a micro-service on top of SOAJS.
...
- index.js: contains the code of the service and the API implementation.
- config.js: contains the configuration of the service.
...
Code Block |
---|
...
|
...
...
|
...
language | js |
---|---|
title | service configuration object |
linenumbers | true |
...
| |
module.exports = { "type": 'service', "prerequisites": { "cpu": '', "memory": '' }, "serviceVersion": 1, "serviceName": "helloworld", |
...
"serviceGroup": "SOAJS Example |
...
Service", |
...
"requestTimeout": 30, "requestTimeoutRenewal": 5, "servicePort": 4020, |
...
"extKeyRequired": false, |
...
"oauth": false, "errors": {}, |
...
"schema": { |
...
"get": { |
...
"/hello": { |
...
"_apiInfo": { |
...
"l": "hello world", "group": |
...
"Example" }, "firstName": { |
...
"source": ['query.firstName'], |
...
"required": true, |
...
"validation": { |
...
"type": "string"
|
...
} }, "lastName": { |
...
"source": ['query.lastName'], |
...
"required": true, |
...
"validation": { |
...
"type": "string" } } } } } }; |
Code Block | ||
---|---|---|
| ||
'use strict'; const soajs = require('soajs'); const config = |
...
require('./config.js'); let service = new soajs.server.service(config); service.init(function() { service.get("/hello", function(req, res) { let name = req.soajs.inputmaskData.firstName + " " + req.soajs.inputmaskData.lastName; res.json(req.soajs.buildResponse(null, "Hello " + name)); }); service.start(); }); |
Simply create the service using SOAJS service constructor, pass along the configuration, initialize it and start implementing the APIs.
...
The Hello World service is available under the soajs.examples repository and soajs framework configuration is available under soajs.utilities.
In the previous page we showed you how to import the configuration for all Get Started Examples.
Now we will show you how to start the service and interact with it.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# go to examples/hello_world and start the service $ cd /opt/soajs/node_modules/soajs.examples/hello_world/ # export necessary environment variables export SOAJS_PROFILE=/opt/soajs/node_modules/soajs.utilities/data/getStarted/profile.jsENV=EXAMPLE export SOAJS_ENVDEPLOY_MANUAL=test1 export SOAJS_REGISTRY_SRVIPAPI=127.0.0.1:21000 # start service $ node . |
Test the Service
...
Once the service starts, run the following curl command that calls the API of your "hello world" service and check out the response returned.
...