Skip to main content

Rest Mapping

The RestMapping is a mapping for performing RESTful HTTP requests. It can make requests using different HTTP methods: GET, PUT, POST and PATCH. The HTTP calls are made through Apache HTTP client, thanks to the ApacheHttpClientRequestHandler class, as follows: HTTPRequestHandler request = HTTPRequestHandlerFactory.getRequestHandler("apache", true); This class implements the HTTPRequestHandler interface, so if at any point we want to replace the HTTP calls with another client (such as WebClient), we simply need to change this line to obtain an object of the corresponding class that implements the interface, such as the WebClientRequestHandler class (note that this class is not fully developed or tested).

Usage

To use the RestMapping in a mapper, you should first prepare the different parts of the request:

  1. Create a body if necessary: Make the transformations to get the body needed for the REST call. For example:
    ticket/subject
    ticket/description
  2. Transform the parts of the request: Once you have the body, you can make the following transformations:
    ticket -->   restcall/request/body
    --> restcall/request/url
    restcall/request/headers/Content-Type
    Note: In the URL, you can use placeholders such as {{endpoint:ticketurl}} (if you have configured an endpoint) or {{msg:ticket/id}}
  3. Apply the corresponding mapping:
    restcall/request ---> RestMapping ---> restcall/response
  4. File Upload Structure: If we want to upload a file, we must create a specific structure for files:
    request/body/attachment/content (The file content as a base64 string)
    request/body/attachment/filename (The name of the file)
    request/body/attachment/contentType (The MIME type of the file, e.g., application/pdf, image/png)
    request/body/attachment/key: Form data key name (name of the file field in the post/put request)
    And apart from the attachment, the fields that the multipart/form-data POST/PUT request needs, for example:
    request/body/description
    A valid example would be:
    request/body/attachment/content: "ACDdkasdjfdfadfsd...."
    request/body/attachment/filename: "printer.png"
    request/body/attachment/contentType: "image/png"
    request/body/attachment/key: "uploaded_data"
    request/body/description: "This is a printer"

These steps ensure that all necessary parts of the request are properly formatted and mapped, allowing for successful RESTful HTTP calls using the RestMapping.

HTTP Output Handling

The output of the HTTP call is displayed in the field specified by the to parameter. If an error occurs during the HTTP request, the last node of the message will be removed, and an error node will be added instead. For example, if to is specified as createticket/response and an error occurs, a new node will be generated as createticket/error.

RestMapping configuration

FieldDescriptionExample
FromDefines the field to which the mapping will be appliedcreateticket/request
ToDefines the field to which the mapping will be appliedcreateticket/response
Function typeDefines the function type. Needs to be "REST Mapping".
FunctionDefines the HTTP methodPOST, PUT, DELETE, PATCH, GET
condition
regex
auditEnables auditing of HTTP callstrue/false/nothing