Send Messages with Postman

Postman is popular development tool allowing to interact with web applications over HTTP. You can use it to communicate with Axon Synapse, to send commands, queries, and events to Axon Server.

Prerequisites

To accomplish the steps in this guide, you need to download and install Axon Synapse, Axon Server, and the Giftcard demo application. Please complete the steps detailed on the Installation page before you continue.

Additionally, you need to download and install Postman. Go to Postman’s download page for detailed instructions.

Examining the Giftcard demo application

In order to manage the Giftcard application, browse to the admin page for the application on port 8081.

A screenshot of the Giftcard demo application UI
Figure 1. A screenshot of the Giftcard demo application UI

By default, the Giftcard application starts up without any gift cards created, however, by using the UI shown above, you can create sample cards with balances.

Send a command from Postman to Giftcard demo via Axon Synapse

To experiment with sending a command over HTTP, you’re going to create a new gift card for $55 with a cardID of, "sample-card-6". Below are the details of the HTTP POST request that Axon Synapse expects.

(1) (2) (3) (4)
POST http://localhost:8080/v1/contexts/default/commands/io.axoniq.demo.giftcard.api.IssueCardCommand
Content-Type: application/xml (5)

<io.axoniq.demo.giftcard.api.IssueCardCommand> (6)
  <id>sample-card-6</id> (7)
  <amount>55</amount> (8)
</io.axoniq.demo.giftcard.api.IssueCardCommand>
1 POST - indicates a POST request
2 http://localhost:8080 - the instance of Axon Synapse
3 /v1/contexts/default/commands/ - sending a command
4 io.axoniq.demo.giftcard.api.IssueCardCommand - the command name
5 The command payload is in XML format
6 The command payload type (the same as the command name in this case)
7 The value of the id field
8 The value of the amount field

The screenshot below shows how you can configure this request in Postman:

A screenshot of the Postman UI
Figure 2. A screenshot of the Postman UI

After sending the request, return back to the admin page for the Giftcard demo app to see that the application issued a new gift card (with a balance of 55$).

A screenshot of the Giftcard demo application UI
Figure 3. A screenshot of the Giftcard demo application UI

You’ve just accomplished all the steps to send a command using an ordinary HTTP POST request to Axon Synapse. Axon Synapse (in turn) relayed the message to Axon Server, which gave the command message to its appropriate command handler.

Send a query from Postman to Giftcard demo via Axon Synapse

To experiment with sending a query over HTTP, list the gift cards you’ve created in the previous section. Read the listing below to see the HTTP POST request that Axon Synapse expects.

(1) (2) (3) (4)
POST http://localhost:8080/v1/contexts/default/queries/io.axoniq.demo.giftcard.api.FetchCardSummariesQuery
AxonIQ-PayloadType: io.axoniq.demo.giftcard.api.FetchCardSummariesQuery (5)
AxonIQ-ResponseType: io.axoniq.demo.giftcard.api.CardSummary (6)
AxonIQ-ResponseCardinality: multiple (7)
Content-Type: application/xml (8)

<io.axoniq.demo.giftcard.api.FetchCardSummariesQuery> (5)
    <offset>0</offset> (9)
    <limit>10</limit> (10)
</io.axoniq.demo.giftcard.api.FetchCardSummariesQuery>
1 POST - indicates a POST request
2 http://localhost:8080 - the instance of Axon Synapse
3 /v1/contexts/default/queries/ - sending a query
4 io.axoniq.demo.giftcard.api.FetchCardSummariesQuery - the query name
5 The payload type
6 The response payload type
7 Expect multiple responses (list)
8 The query payload is in XML format
9 The value of the offset field
10 The value of the limit field

The screenshot below shows how you can configure this request in Postman:

A screenshot of the Postman UI
Figure 4. A screenshot of the Postman UI

Publish an event from Postman to Giftcard demo via Axon Synapse

To experiment with publishing an event over HTTP, you’ll redeem an amount from an already existing gift card. Read the listing below to see the HTTP POST request that Axon Synapse expects.

(1) (2) (3) (4)
POST http://localhost:8080/v1/contexts/default/events/io.axoniq.demo.giftcard.api.CardRedeemedEvent
AxonIQ-AggregateId: sample-card-6 (5)
AxonIQ-AggregateType: Giftcard (6)
AxonIQ-SequenceNumber: 1 (7)
Content-Type: application/json (8)

{
    "id": "sample-card-6", (9)
    "amount": 4 (10)
}
1 POST - indicates a POST request
2 http://localhost:8080 - the instance of Axon Synapse
3 /v1/contexts/default/events/ - sending a query
4 io.axoniq.demo.giftcard.api.CardRedeemedEvent - the event name
5 The aggregate ID
6 The aggregate type
7 The event sequence number
8 The event payload is in JSON format
9 The value of the id field
10 The value of the amount field

The screenshot below shows how you can configure this request in Postman:

A screenshot of the Postman UI
Figure 5. A screenshot of the Postman UI

Return to the admin page for the Giftcard demo app to confirm the system deducted the amount from the gift card.

A screenshot of the Giftcard demo application UI
Figure 6. A screenshot of the Giftcard demo application UI

Alternatively, you can look at the Search Page on the Axon Server Dashboard

A screenshot of Axon Server’s Dashboard
Figure 7. A screenshot of Axon Server’s Dashboard