OS1 Concepts

Custom Code

7min

Overview

The logistics industry handles a wide range of operations that deals with both the forward and the reverse flow of goods and services. It works on a point-to-point basis with the number of milestones between origin and point of delivery. Handling the operations and providing relevant information can be unique for each company according to its business logic. In such cases, the biggest challenge is to provide a technical layer that could meet each business’s requirements and to provide the scope of enhancing the logic layer in the future.

Custom Code support in CoreOS can help developers implement business-specific logic in their applications at different places.

About Custom Code

Custom code helps the developers in defining the rules that govern the complete operational cycle. According to their needs, developers can configure Custom Code in the existing Core API services, such as Order, Dispatch, Entity, Container, and Participant.

Developers can modify the Core API services for creation, management, and execution in a self-service model. Here, we will further help you to understand the overall functionality and use of Custom Code.

CoreOS services that support Custom Code configuration functionality are:

Note: The link for implementing Custom Code is provided with each service.

Benefits of Using Custom Code

  • Earlier, the developer would build wrappers on CoreOS services for validation and enrichment. This would require the building of a complex validation layer and multiple API calls were required on top of Core APIs. Implementing this layer was quite hard for any real-time-based application as requests would require validations each time they are called in CoreOS services. This issue is resolved with the introduction of Custom Code.
  • It helps in reducing the developer’s efforts to write the complete code structure. Rather, configure the pre-defined Custom Code for the service it is associated with, and use the pre-defined structure code for the rest of the services.
  • Developers can patch in their custom business logic for corresponding CoreOS services using Custom Code libraries available for different services. This can be done in a self-service manner.

Use Cases of Custom Code

Different categories where Custom Code is applicable:

Method Validation: While updating a value of an attribute, the method/function/code can check for attribute values of objects in the same service or a different service.

Example: Any billing method changes in the billing service should be notified to the relevant user groups/downstream services.

State Changes: A subset of Method Validation, this point caters to the state change of objects. Objects have states and they move from one state to another based on predefined rules. These rules vary from one business to another and depend on the values of attributes belonging to the same or different CoreOS service or an external application.

Example: For a client state to be changed to ‘Active’, there can be checks on the pricing information (from a pricing service) or attributes of the same client object or a third-party API service that determines the rules of activation.

Data Enrichment: Populating the values of attributes of an object at any point in the life cycle of that object in CoreOS.

Example: Waybill prefixes for a client are generated based on predetermined rules and used for any new waybills.

Custom Code Implementation

There are two ways to provide Custom Code:

  • Pre-configured Custom Code Pre-configured Custom Code can be registered using the handlers. It will be invoked before calling the API and applied for all the requests for a type.
  • In the Request body Custom Code can be passed along with the request body if it has to be applied for a single request such as a create/update instance. There are two attributes added for all non-GET APIs (except types).

Attributes

  1. onRequest
    1. The request body of the OnRequest CustomCode URL is the input of the API.
    2. No custom request body can be passed for the OnRequest CustomCode API call.
    3. If OnRequest fails, OnError is executed.
    4. Notification is not sent if OnRequest fails.
  2. OnError
    1. The request body of the OnError CustomCode URL is the input of the API.
    2. Error message related to the OnRequest API call is passed for the OnError CustomCode API call.
    3. If OnError fails, the custom API response will be returned as a new field customApiResponse.
    4. Notification is not sent if OnError fails.