Create Projection Definition
post
https://api.serialized.io
/projections/definitions
Create a new projection definition

Example

cURL
Java
C#
Node
1
curl -i https://api.serialized.io/projections/definitions \
2
--header "Content-Type: application/json" \
3
--header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
4
--header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
5
--data '
6
{
7
"projectionName": "orders",
8
"feedName": "order",
9
"handlers": [
10
{
11
"eventType": "OrderPlacedEvent",
12
"functions": [
13
{
14
"function": "set",
15
"targetSelector": "$.projection.status",
16
"rawData": "PLACED"
17
},
18
{
19
"function": "set",
20
"targetSelector": "$.projection.orderAmount",
21
"eventSelector": "$.event.orderAmount"
22
}
23
]
24
}
25
]
26
}
27
'
Copied!
1
import com.google.common.collect.ImmutableMap;
2
import javax.ws.rs.client.Client;
3
import javax.ws.rs.client.ClientBuilder;
4
5
Client client = ClientBuilder.newClient();
6
URI apiRoot = URI.create("https://api.serialized.io");
7
8
Map<String, Object> projectionDefinition = ImmutableMap.of(
9
"projectionName", "orders",
10
"feedName", "order",
11
"handlers", ImmutableList.of(
12
ImmutableMap.of(
13
"eventType", "OrderPlacedEvent",
14
"functions", ImmutableList.of(
15
ImmutableMap.of(
16
"function", "set",
17
"targetSelector", "$.projection.status",
18
"rawData", "PLACED"
19
),
20
ImmutableMap.of(
21
"function", "set",
22
"targetSelector", "$.projection.orderAmount",
23
"eventSelector", "$.event.orderAmount"
24
)
25
)
26
27
)
28
)
29
);
30
31
Response response = client.target(apiRoot)
32
.path("projections")
33
.path("definitions")
34
.request()
35
.header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
36
.header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
37
.post(Entity.json(projectionDefinition));
Copied!
1
using System;
2
using System.Collections.Generic;
3
using RestSharp;
4
5
var definition = new Dictionary<string, Object>
6
{
7
{ "projectionName", "orders" },
8
{ "feedName", "order" },
9
{ "handlers", new List<Dictionary<string, Object>>
10
{
11
new Dictionary<string, Object>
12
{
13
{"eventType", "OrderPlacedEvent"},
14
{"functions", new List<Dictionary<string, Object>>
15
{
16
new Dictionary<string, Object>
17
{
18
{"function", "set"},
19
{"targetSelector", "$.projection.status"},
20
{ "rawData", "PLACED"}
21
},
22
new Dictionary<string, Object>
23
{
24
{"function", "set"},
25
{"targetSelector", "$.projection.orderAmount"},
26
{ "eventSelector", "$.event.orderAmount"}
27
}
28
}
29
}
30
}
31
}
32
}
33
};
34
35
var request = new RestRequest("projections/definitions", Method.POST)
36
.AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
37
.AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");
38
.AddJsonBody(definition);
39
40
var response = client.Execute(request);
Copied!
1
const axios = require("axios");
2
3
const client = axios.create({
4
baseURL: "https://api.serialized.io",
5
headers: {"Serialized-Access-Key": "<YOUR_ACCESS_KEY>"},
6
headers: {"Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"}
7
});
8
9
const definition = {
10
projectionName: "orders",
11
feedName: "order",
12
handlers: [
13
{
14
eventType: "OrderPlacedEvent",
15
functions: [
16
{
17
"function": "set",
18
"targetSelector": "$.projection.status",
19
"rawData": "PLACED"
20
},
21
{
22
"function": "set",
23
"targetSelector": "$.projection.orderAmount",
24
"eventSelector": "$.event.orderAmount"
25
}
26
]
27
}
28
]
29
};
30
31
client.post("projections/definitions", definition)
32
.then(function (response) {
33
// Handle response
34
})
35
.catch(function (error) {
36
// Handle error
37
});
Copied!
Last modified 20d ago