Single and batch posting using HTTP API (3.0.1)

I see a difference when sending events as either a single event, or in a batch.

My contents for a single event looks like:

{

“eventType”:“TestEvent”,

“eventId”:“2c5706e5-60f0-47cc-8865-41b15eee6b89”,

“data”:{

“name”:“Name of the first event”

}

}

``

I post it to the Event Store using:

curl -i -d @es_single_test.txthttp://192.168.59.103:2113/streams/newstream” -H “Content-Type:application/json” -H “ES-EventType:TestEvent” -L

``

In the Event Store I see data received is:

{
  "eventType": "TestEvent",
  "eventId": "2c5706e5-60f0-47cc-8865-41b15eee6b89",
  "data": {
    "name": "Name of the first event"
  }
}

``

… which is just what I expected.

BUT!

My contents for a batch of three events looks like:

[

{

“eventType”:“TestEvent”,

“eventId”:“405706e5-60f0-47cc-8865-41b15eee6b89”,

“data”:{

“name”:“Name of the first event”

}

},

{

“eventType”:“TestEvent”,

“eventId”:“0cbbb514-6c7f-447c-90a8-fcb65104d143”,

“data”:{

“name”:“Name of the second event”

}

},

{

“eventType”:“TestEvent”,

“eventId”:“3b802922-7496-4b2c-b0a6-7bf9b7b8ad2f”,

“data”:{

“name”:“Name of the third event”

}

}

]

``

I post it to the Event Store using:

curl -i -d @es_batch_test.txthttp://192.168.59.103:2113/streams/newstream” -H “Content-Type:application/vnd.eventstore.events+json” -L

``

In the Event Store I see data received are three separate events (which is perfect). However, each event has the following data (taken the first one only here):

{
  "name": "Name of the first event"
}

``

… What happened with the “eventType”, “eventId”? Why is it different than when I send a single event?

Hi,

You’re indeed hitting the difference between single and batched events. If you post with the content type ‘application/json’ and an ES-EventType header, it’s assumed that the entire body of the post is the event. However, in order to post a batch you must use
our custom media type ‘application/vnd.eventstore.events+json’.

The behaviour you’re seeing in the second situation is correct. To get matching behaviour in the first, modify your single event file to look like this:

[{

"eventType":"TestEvent",

"eventId":"2c5706e5-60f0-47cc-8865-41b15eee6b89",

"data":{

"name":"Name of the first event"

}

}]

And post your request without the ES-EventType header, and with the application/vnd.eventstore.events+json content type. Things like Event ID and Event Type are presented out of band as part of the atom feed rather than as part of the data itself.

James

More on this topic is covered here as well
http://docs.geteventstore.com/http-api/3.0.1/writing-to-a-stream/
including the not including of an event id but having the backend
generate it for you via a redirect.

Greg