Skip to content

Locally Simulate HTTP Requests

This guide will get you familiar with writing code in an integration and invoking that code on your local machine.

Asynchronous events originating from the Event Registry cannot be sent from non-local environments to your local machine. To test locally, you can simulate an event by calling the HTTP endpoint that IFX provides.

Prerequisites

Run a local server

To spin up a local server where local code can be tested, issue the command npm run localTestingServer

When the server has started successfully, it will look like this:

Terminal window
> @myorg/myorg-my-ifx-integration@1.0.0 localTestingServer
> node node_modules/@arcxp/arcxp-ifx-node-sdk/localTestingServer
Loading environment configuration for env: development
Local Express Server Started at http://127.0.0.1:8080/ifx/local/invoke

http://127.0.0.1:8080/ifx/local/invoke can now be used to POST event messages to and invoke integrations locally.

Event payload model

All events, except for custom events, will have the same fundemental structure:

{
"organizationId": "string",
"key": "string",
"typeId": "int",
"uuid": "string",
"currentUserId": "string",
"version": "int",
"invocationId": "string",
"body": {"PAYLOAD BODY HERE"}
}

The body serves as the designated area for event data, and its structure can be customized to meet any specific requirements by the event originating application.

For example, the websked:edition_finalize event will send the following event message:

{
"organizationId": "myorgname",
"key": "websked:edition_finalize",
"typeId": 1,
"uuid": "",
"currentUserId": "",
"version": 2,
"invocationId": "ABCD-123534R4-DAFSDFA-8363",
"body": {
"type": "edition_finalize",
"orgId": "string",
"publication": {
"name": "string",
"publicationId": "string",
"editionId": "string",
"editionTime": "number",
"editionUrl": "string",
"storyIds": [
"string"
],
"sectionId": "string",
"website": "string",
"publicationSetId?": "string"
}
}
}

Test it out

Let’s take a very simple (made up) event message so we can see it working:

  1. Navigate to the integration directory where you have a handler ready to go. You can have something as simple as:

    src/eventsHandlers/updateHandler.js
    const updateHandler = async (event) => {
    console.log(event)
    console.log("inside story updateHandler")
    return "hooray!"
    }
    module.exports = updateHandler

    Make sure you included the event name and handler in src/eventsRouter.json:

    {
    "updateHandler": [
    "story:update"
    ]
    }
  2. Start local server npm run localTestingServer

  3. Use Postman (or cURL) to POST a payload to the local server POST http://127.0.0.1:8080/ifx/local/invoke/ and include the JSON below as the POST body:

    {
    "organizationId": "myorg",
    "key": "story:update",
    "version": 2,
    "invocationId": "12345678-90ce-4e72-bf72-10bfb0e4186d",
    "body": {
    "my_data": "Hello!!!!!"
    }
    }

    In the Postman console we can see the return message from our handler code:

    Postman response example

    and back in our code editor, the result of console.log(event):

    code editor logging event.body.my_data

How to get a “real” payload model

Each application that send events to IFX defines its own payload inside of the event.body, such as Composer's Send to Print event.

You can get the payload model of events you are trying to simulate from the Event Menu. In cases where the payload is not provided:

  1. Create test event handlers for each event you are researching so you can console log the event payload
  2. Map those events to the handler
  3. Ensure useful logging is in place i.e. console.log(event)
  4. Bundle, deploy and promote the integration to Sandbox
  5. Trigger the event you need by performing an action, such as updating a story
  6. Query the logs to view the payload

Save the payload so you can easily adjust minor data points locally, like the headline, to generate new scenarios.



Have a feature request or suggestion? Let us know on Our Ideas Portal.