Skip to content

xprt64/dudulina-eventstore-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dudulina-eventstore-api

A Restful HTTP API for a Dudulina Event Store

It is a HTTP interface to read the events from the Mongolina wich is an Event store implementation for Dudulina CQRS framework.

The idea behind this project is to permit the building of Read models in any programming language, not only PHP.

Listing of events from all Aggregate streams

By accesing /events one can view the list of all events from the Event store, in the order they where emitted. The order of events is given by a MongoDB Timestamp that is synchronized by vector clocks even among shards.

The list can be filtered by the eventClass, limit-ed or after a Timestamp. See the RAML file for a complete description.

Examples:

  • http://localhost/events?after=[19:1519816953]&limit=10 - it gets the first 10 events after the timestamp [19:1519816953]
  • http://localhost/events?classes[]=SomeEventClass - it gets the events that have the class SomeEventClass
  • http://localhost/events?classes[]=SomeEventClass1&classes[]=SomeEventClass2 - it gets the events that have the class SomeEventClass1 or SomeEventClass2

An example of output:

{
 "events": [
      {
        "id": "59eebbf2f82c3b2ec048c6a4",
        "type": "Crm\\Write\\Authentication\\Event\\UserWasAuthenticated",
        "payload": {
          "idUser": "e6ac8ab4a1a6e1064429b94d",
          "some": "other data",
        },
        "aggregate": {
          "id": "e6ac8ab4a1a6e1064429b94d",
          "type": "Crm\\Write\\AuthenticationAggregate",
          "stream": "6f3540f9d731a88e5c8b828d",
          "version": 1,
          "links": {
            "stream": "http://localhost/aggregate?aggregateClass=Crm\\Write\\AuthenticationAggregate&aggregateId=e6ac8ab4a1a6e1064429b94d&after=-1"
          }
        },
        "meta": {
          "createdAt": "2018-01-09T13:58:17+00:00",
          "createdBy": null,
          "ts": "[1:1519816953]",
          "command": null
        },
        "links": {
          "self": "http://localhost/events/59eebbf2f82c3b2ec048c6a4"
        }
      }
   ]
 }

The list is navigable to the next chunk of events by containing a links attribute:

{  
  "links": {
    "first": "http://localhost/events?after=[1:1]&limit=10",
    "next": "http://localhost/events?after=[19:1519816953]&limit=10"
  }
}

The page contains also some performance statistics:

{  
  "stats": {
    "pageLoadDuration": 0.041680097579956055,
    "queryFetchDuration": 0.019011974334716797
  }
}

Listing of events from one Aggregate only

Every returned event contains also a link to the events generated by a single Aggregate instance only.

 {
 "aggregate": {
      "id": "e6ac8ab4a1a6e1064429b94d",
      "type": "Crm\\Write\\AuthenticationAggregate",
      "stream": "6f3540f9d731a88e5c8b828d",
      "version": 1,
      "links": {
        "stream": "http://localhost/aggregate?aggregateClass=Crm\\Write\\AuthenticationAggregate&aggregateId=e6ac8ab4a1a6e1064429b94d&after=-1"
      }
    }
}

The list can be limit-ed or filtered to return only the events after a version. See the RAML file for a complete description.

Examples:

  • http://localhost/aggregate?aggregateClass=Crm\\Write\\AuthenticationAggregate&aggregateId=e6ac8ab4a1a6e1064429b94d&after=-1 - it gets the first 10 events from the begining of the Aggregate lifetime

The list is navigable to the next chunk of events by containing a links section with a next url, which is present only if there are more items.

API description

This API is described by a RAML file.

Installing - deploy

The API can be deployed using docker using the Dockerfile. The only configuration is the Mongo connect string that can passed as environment variable named MONGO_EVENT_STORE_DSN.

docker build -t event-store/http-api . && \
docker run -e MONGO_EVENT_STORE_DSN=mongodb://localhost:27017/eventStore -p "80:80" event-store/http-api

You can use docker secrets instead of clear-text passwords:

docker build -t event-store/http-api . && \
docker run -e MONGO_EVENT_STORE_DSN=mongodb://{/run/secrets/MONGODB_CREDENTIALS}localhost:27017/eventStore -p "80:80" event-store/http-api