Skip to content

Listing Event Types

This guide shows how to list the existing event types from EventSourcingDB using its HTTP API. You'll learn how to retrieve all event types that have been used so far.

Listing All Event Types

To retrieve the list of all known event types, send an HTTP request using POST to the /api/v1/read-event-types endpoint:

curl \
  -i \
  -X POST \
  -H "authorization: Bearer <API_TOKEN>" \
  http://localhost:3000/api/v1/read-event-types

If everything worked as expected, the server will respond with HTTP status code 200 OK:

HTTP/1.1 200 OK

The response body will then contain a list of all event types that have been used in stored events. If you've followed the steps in Writing Events, you should see the following event types:

{
  "type": "eventType",
  "payload": {
    "eventType": "io.eventsourcingdb.library.book-acquired",
    "isPhantom": false
  }
}
{
  "type": "eventType",
  "payload": {
    "eventType": "io.eventsourcingdb.library.book-borrowed",
    "isPhantom": false
  }
}

In reality, the output will look slightly different – the event types are returned as compact NDJSON, with each event type occupying a single line.

Schemas Included

If you have previously registered a schema for an event type, the payload will also contain the schema.

A Word on Phantom Event Types

You may have noticed that the response not only includes the event types themselves, but also indicates whether each event type is considered a phantom.

This raises the question: when is an event type considered a phantom?

  • An event type is a phantom if EventSourcingDB knows already about this event type, although no events of that type have been written yet (e.g., because a JSON schema was registered for the given event type).
  • An event type is not a phantom if at least one event of that type exists.

Listing a Specific Event Type

In some cases, you may want to retrieve detailed information about a specific event type. To do so, send an HTTP request using POST to the /api/v1/read-event-type endpoint and include the event type you are interested in as JSON in the request body:

curl \
  -i \
  -X POST \
  -H "authorization: Bearer <API_TOKEN>" \
  -H "content-type: application/json" \
  -d '{ "eventType": "io.eventsourcingdb.library.book-acquired" }' \
  http://localhost:3000/api/v1/read-event-type

If everything worked as expected, the server will respond with HTTP status code 200 OK and return a flat JSON object with all details about the event type:

{
  "eventType": "io.eventsourcingdb.library.book-acquired",
  "isPhantom": true,
  "schema": {
    "...": "..."
  }
}