Server scripts

Server scripts can be used to implement your microservice’s service interface and business logic. The core engine that powers Neptune DXP is based on Node.js, often used in its native form as a microservices runtime. Neptune DXP provides an embedded interactive Script Editor to author Node.js server scripts and adds value taking away various boilerplate tasks associated with file management.

For example, let’s consider a customer microservice with a /wishlists resource. The service interface may include several REST API operations (POST/PUT/PATCH/GET/DELETE) to maintain the customer’s wishlists. Normally, you need to:

  • Define associate it with the REST operation and a controller script handling the request.

  • Implement the router script logic.

  • Implement the controller script logic.

With Neptune DXP you can accelerate this process and limit the amount of boilerplate code needed to animate your service interface:

microservice4

You define the controller script in the Neptune DXP Cockpit and Neptune DXP handles all details about its placement and execution status in the Node.js server. As there will be multiple operations to be handled by corresponding controller scripts, it is valuable to categorize all controllers into a dedicated project. Similarly, other scripts for other tasks such as workflows, jobs, orchestrations, can also be tagged accordingly.

Once the script is defined and your business logic is implemented you simply associate it with your endpoint operation in the API Designer. Neptune DXP takes care of the routing and population of all the request elements, such as parameters, headers, and body data models, readily accessible to the controller script.

With some UI driven steps you can build a complete microservice API interface to surface its function to its consumers. Similar capabilities can be found elsewhere in workflow management or job scheduling where Server Scripts are extensively used and associated with other Neptune DXP resources to implement your business logic.