Skip to main content

HTTP API

ReSolve exposes an HTTP API that allows you to send aggregate commands, and query Read and View Models.

Command APIā€‹

You can send a command from the client side as a POST request to the following URL:

http://{host}:{port}/api/commands

The request body should have the application/json content type and contain the command's JSON representation.

{
"aggregateName": aggregateName,
"type": commandType,
"aggregateId": aggregateID,
"payload": {
"param1": value1,
"param2": value2,
...
"paramN": valueN
}
}
NameTypeDescription
aggregateIdstringThe ID of an aggregate that should handle the command.
aggregateNamestringThe aggregate's name as defined in config.app.js.
commandTypestringThe command type that the aggregate can handle.
payloadobjectParameters the command accepts.

Exampleā€‹

const apiCommandsUrl = '/api/commands'

const sendCommand = async ({
aggregateName,
aggregateId,
type,
payload,
jwt,
}) => {
await fetch(apiCommandsUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwt}`,
},
body: JSON.stringify({
aggregateName,
aggregateId,
type,
payload,
}),
})
}

Read Model APIā€‹

To query a Read Model from the client side, send a POST request to the following URL:

http://{host}:{port}/api/query/{readModel}/{resolver}

URL Parameters:ā€‹

NameDescription
readModelThe Read Model name as defined in the application's configuration file.
resolverThe name of a resolver defined in the Read Model.

The request body should have the application/json content type and the following structure:

{
param1: value1,
param2: value2,
// ...
paramN: valueN
}

The object contains parameters that the resolver accepts.

Exampleā€‹

const apiQueryUrl = '/api/query'

const queryReadModel = async (readModelName, resolver, parameters, jwt) => {
const requestUrl = `${apiQueryUrl}/${readModelName}/${resolver}`
const res = await fetch(requestUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwt}`,
},
body: JSON.stringify(parameters),
})
return await res.json()
}

View Model APIā€‹

To query a View Model from the client side, send a GET request to the following URL:

http://{host}:{port}/api/query/{viewModel}/{aggregateIds}

URL Parametersā€‹

NameDescription
viewModelThe View Model name as defined in the application's configuration file.
aggregateIdsThe comma-separated list of Aggregate IDs to include in the View Model. Use * to include all Aggregates.

Exampleā€‹

const apiQueryUrl = '/api/query'

const queryViewModel = async (viewModelName, aggregateIds, jwt) => {
const requestUrl = `${apiQueryUrl}/${viewModelName}/${aggregateIds.join(',')}`
const res = await fetch(requestUrl, {
method: 'GET',
headers: {
Authorization: `Bearer ${jwt}`,
},
})
return await res.json()
}

Authorizationā€‹

To authorize your request on a reSolve server, specify a Bearer Token in your request's Authorization header:

await fetch(Url, {
...
headers: {
Authorization: `Bearer ${jwt}`,
...
},
...
})

See the Authentication and Authorization topic for information on how authorization is handled on the server.