Projection API reference

Full reference for the Projection API

Create projection definition

Create a new projection definition

Example

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"
        }
      ]
    }
  ]
}
'
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));s
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);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "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
  });

Get projection definition

Get a projection definition

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/projections/definitions/order
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 response = client.target(apiRoot)
  .path("projections")
  .path("definitions")
  .path("orders")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
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 response = client.target(apiRoot)
  .path("projections")
  .path("definitions")
  .path("orders")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.get("projections/definitions/orders")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Update projection definition

Update a projection definition

Example

curl -i https://api.serialized.io/projections/definitions/orders \
  --header "Content-Type: application/json" \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  -X PUT \
  --data '
  {
  "projectionName": "orders",
  "feedName": "order",
  "handlers": [
    {
      "eventType": "OrderPlacedEvent",
      "functions": [
        {
          "function": "set",
          "targetSelector": "$.projection.status",
          "rawData": "PLACED"
        },
        {
          "function": "set",
          "targetSelector": "$.projection.orderAmount",
          "eventSelector": "$.event.orderAmount"
        }
      ]
    }
  ]
}
'
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")
  .path("orders")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .put(Entity.json(projectionDefinition));
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/{projectionName}", Method.PUT)
   .AddUrlSegment("projectionName", "orders")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");
   .AddJsonBody(definition);

var response = client.Execute(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "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.put("projections/definitions/orders", definition)
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Delete projection definition

Delete a projection definition

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  -X DELETE https://api.serialized.io/projections/definitions/orders
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");

  Response response = client.target(apiRoot)
  .path("projections")
  .path("definitions")
  .path("orders")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .delete();
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("projections/definitions/{projectionName}", Method.DELETE)
   .AddUrlSegment("projectionName", "orders")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.delete("projections/definitions/orders")
  .then(function (response) {
    // Hnadle response
  })
  .catch(function (error) {
    // Handle error
  });

List projection definitions

List projection definitions

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/reactions/definitions
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 response = client.target(apiRoot)
  .path("reactions")
  .path("definitions")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("reactions/definitions", Method.GET)
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.get("reactions/definitions")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Get projections overview

Returns high-level information about all projections, including projection names and count.

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/projections
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 response = client.target(apiRoot)
  .path("projections")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("projections", Method.GET)
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.get("projections")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Get single projection

Get a single projection instance.

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/projections/single/orders/84e3565e-cd61-44e7-9769-c4663588c4dd
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 response = client.target(apiRoot)
  .path("projections")
  .path("single")
  .path("orders")
  .path("84e3565e-cd61-44e7-9769-c4663588c4dd")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("projections/single/{projectionName}/{projectionId}", Method.GET)
   .AddUrlSegment("projectionName", "orders")
   .AddUrlSegment("projectionId", "84e3565e-cd61-44e7-9769-c4663588c4dd")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.get("projections/single/orders/84e3565e-cd61-44e7-9769-c4663588c4dd")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Get single projection count

Get count for a single projection type.

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/projections
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 response = client.target(apiRoot)
  .path("projections")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("projections", Method.GET)
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.get("projections")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

List single projections

Get count for a single projection type.

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/projections/single/orders
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 response = client.target(apiRoot)
  .path("projections")
  .path("single")
  .path("orders")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("projections/single/{projectionName}", Method.GET)
   .AddUrlSegment("projectionName", "orders")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.get("projections/single/orders")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Rebuild single projections

This call deletes all existing projections and starts a rebuild from the beginning of the event history. Keep in mind that this might take a while.

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  -X DELETE https://api.serialized.io/projections/single/orders
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

Client client = ClientBuilder.newClient();
  URI apiRoot = URI.create("https://api.serialized.io");

  Response response = client.target(apiRoot)
  .path("projections")
  .path("single")
  .path("orders")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .delete();

using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("projections/single/{projectionName}", Method.DELETE)
   .AddUrlSegment("projectionName", "orders")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.delete("projections/single/orders")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Get aggregated projection

Retrieves an aggregated Projection

Example

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/projections/aggregated/order-totals
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 response = client.target(apiRoot)
  .path("projections")
  .path("aggregated")
  .path("order-totals")
  .request()
  .header("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
  .header("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>")
  .get(Map.class);
using RestSharp;
using System;

var client = new RestClient("https://api.serialized.io");

var request = new RestRequest("projections/aggregated/{projectionName}", Method.GET)
   .AddUrlSegment("projectionName", "order-totals")
   .AddHeader("Serialized-Access-Key", "<YOUR_ACCESS_KEY>")
   .AddHeader("Serialized-Secret-Access-Key", "<YOUR_SECRET_ACCESS_KEY>");

var response = client.Execute<Dictionary<string, Object>>(request);
const axios = require("axios");

const client = axios.create({
  baseURL: "https://api.serialized.io",
  headers: {
    "Serialized-Access-Key": "<YOUR_ACCESS_KEY>",
    "Serialized-Secret-Access-Key": "<YOUR_SECRET_ACCESS_KEY>"
  }
});

client.get("projections/aggregated/order-totals")
  .then(function (response) {
    // Handle response
  })
  .catch(function (error) {
    // Handle error
  });

Rebuild aggregated projection

Rebuilds an aggregated projection by replaying all events from the beginning of the event history.