Skip to content
This repository

Event sourcing example with Scala and Akka

branch: master
README.md

News

  • 11 Aug 2012: A successor of this example application is available here. It is based on the eventsourced library, a library for building reliable, scalable and distributed event-sourced applications in Scala.
  • 23 Feb 2012: Work on branch play replaces the Jersey and Scalate-based web layer with Play Framework 2.0

Blog

Part Branch
Building an Event-Sourced Web Application - Part 1: Domain Model, Events and State part-1
Building an Event-Sourced Web Application - Part 2: Projections, Persistence, Consumers and Web Interface part-2

Run

sbt run-main dev.example.eventsourcing.server.Webserver

Then go to http://localhost:8080 and create some invoices.

Web API

The example application's RESTful service interface supports HTML, XML and JSON as representation formats. Content negotiation is done via the Accept HTTP header. The following examples show how to get different representations of invoice-3

HTML

Enter http://localhost:8080/invoice/invoice-3 into your browser. Provided you have created an invoice with id invoice-3 before you should see something like

invoice-3

XML

curl -H "Accept: application/xml" http://localhost:8080/invoice/invoice-3

yields

<draft-invoice id="invoice-3" version="2">
    <total>12.8</total>
    <sum>12.8</sum>
    <discount>0</discount>
    <items>
        <item>
            <description>item-1</description>
            <count>1</count>
            <amount>4.1</amount>
        </item>
        <item>
            <description>item-2</description>
            <count>3</count>
            <amount>2.9</amount>
        </item>
    </items>
</draft-invoice>

JSON

curl -H "Accept: application/json" http://localhost:8080/invoice/invoice-3

yields

{
 "draft-invoice":
 {
  "@id":"invoice-3",
  "@version":"2",
  "total":"12.8",
  "sum":"12.8",
  "discount":"0",
  "items":
  {
   "item":
   [
   {
    "description":"item-1",
    "count":"1",
    "amount":"4.1"
   },
   {
    "description":"item-2",
    "count":"3",
    "amount":"2.9"
   }
   ]
  }
 }
}
Something went wrong with that request. Please try again.