Create Projection Definition

post
Create a new projection definition

https://api.serialized.io/projections/definitions
Create a new reaction definition
Request
Response
Request
Headers
Serialized-Access-Key
required
string
Serialized access key
Serialized-Secret-Access-Key
required
string
Serialized secret key
Body Parameters
signingSecret
optional
string
Secret used in HMAC signing of outgoing request to custom projection function.
idField
optional
string
Field in the Projection to use as id field in queries. Defaults to the aggregate id.
aggregated
optional
boolean
If true, creates an aggregated Projection. Default: false
projectionName
required
string
Name of the projection type
feedName
required
string
Name of the feed
handlers
required
array
Handlers for the reaction. See examples below.
Response
200: OK
Projection definition successfully created
409: Conflict
If projection name is not unique
422: Unprocessable Entity
If request body is invalid

Example

cURL
Java
C#
Node
cURL
curl -i https://api.serialized.io/projections/definitions \
--header "Content-Type: application/json" \
--header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
--header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
--data '
{
"projectionName": "orders",
"feedName": "order",
"handlers": [
{
"eventType": "OrderPlacedEvent",
"functions": [
{
"function": "set",
"targetSelector": "$.projection.status",
"rawData": "PLACED"
},
{
"function": "set",
"targetSelector": "$.projection.orderAmount",
"eventSelector": "$.event.orderAmount"
}
]
}
]
}
'
Java
import com.google.common.collect.ImmutableMap;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
Client client = ClientBuilder.newClient();
URI apiRoot = URI.create("https://api.serialized.io");
Map<String, Object> projectionDefinition = ImmutableMap.of(
"projectionName", "orders",
"feedName", "order",
"handlers", ImmutableList.of(
ImmutableMap.of(
"eventType", "OrderPlacedEvent",
"functions", ImmutableList.of(
ImmutableMap.of(
"function", "set",
"targetSelector", "$.projection.status",
"rawData", "PLACED"
),
ImmutableMap.of(
"function", "set",
"targetSelector", "$.projection.orderAmount",
"eventSelector", "$.event.orderAmount"
)
)
)
)
);
Response response = client.target(apiRoot)
.path("projections")
.path("definitions")
.request()
.header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
.header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
.post(Entity.json(projectionDefinition));
C#
using System;
using System.Collections.Generic;
using RestSharp;
var definition = new Dictionary<string, Object>
{
{ "projectionName", "orders" },
{ "feedName", "order" },
{ "handlers", new List<Dictionary<string, Object>>
{
new Dictionary<string, Object>
{
{"eventType", "OrderPlacedEvent"},
{"functions", new List<Dictionary<string, Object>>
{
new Dictionary<string, Object>
{
{"function", "set"},
{"targetSelector", "$.projection.status"},
{ "rawData", "PLACED"}
},
new Dictionary<string, Object>
{
{"function", "set"},
{"targetSelector", "$.projection.orderAmount"},
{ "eventSelector", "$.event.orderAmount"}
}
}
}
}
}
}
};
var request = new RestRequest("projections/definitions", Method.POST)
.AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
.AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");
.AddJsonBody(definition);
var response = client.Execute(request);
Node
const axios = require("axios");
const client = axios.create({
baseURL: "https://api.serialized.io",
headers: {"Serialized-Access-Key": "<YOUR_ACCESS_KEY>"},
headers: {"Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"}
});
const definition = {
projectionName: "orders",
feedName: "order",
handlers: [
{
eventType: "OrderPlacedEvent",
functions: [
{
"function": "set",
"targetSelector": "$.projection.status",
"rawData": "PLACED"
},
{
"function": "set",
"targetSelector": "$.projection.orderAmount",
"eventSelector": "$.event.orderAmount"
}
]
}
]
};
client.post("projections/definitions", definition)
.then(function (response) {
// Handle response
})
.catch(function (error) {
// Handle error
});