Skip to main content

Version: 24.10

Mock during development

While developing with Open UX, you probably don't want to send data to a live instance of Journey Manager. To account for this, the Open UX CLI provides a mock command that launches a mock server on your local machine.

The purpose of a mock server is to simulate a real-world API. For example, the server provided by the transact mock command can handle all of the same GET and POST requests as the Journey Manager API, but rather than those requests hitting an instance of Journey Manager, they hit the server that's running on your local machine. This allows you to develop applications with near-instant response times for API calls.

Launching a Mock Server

tip

If you're using the React template and have already launched the local server with the npm run start or yarn start commands, you don't need to launch the mock server. The mock server will automatically be launched for you.

To launch the mock server, open a terminal and navigate to your project's directory:

cd your-project-name

Then run the transact mock command:

transact mock

This starts a local server available at http://localhost:9999. You can stop this server by pressing CTRL+C in the terminal or by closing the terminal window.

Custom Routes

If you wish to provide your own routes, you can do so by creating a routes file and using the --routes option.

Each key represents an endpoint, however there are special keys for each Transact API call such as formLoad. To learn more, see API Reference > Core Client API.

The routes file can be in JSON or Javascript.

{
"addresses": [{ "line1": "10 Fake Street", "state": "NSW" }],
"formLoad": {
"formStatus": "Saved",
"formData": {
"Applicant": {
"FirstName": "John",
"LastName": "Doe"
}
}
}
}

Running the --routes option:

transact mock --routes mocks/routes.json

You can also generate a default routes JSON file by running the following command:

transact mock --generate mocks

Command options

Here is a complete list of options avaiable for the transact mock command.

Usage: mock [options]

provides Open UX API mocking via running an express server

Options:

-r, --routes <path> path to routes file (json or js)
-g, --generate <path> generate an example routes file
-h, --help output usage information

To see this list on the command line, run the transact mock command with the --help flag:

transact mock --help