Skip to content

vvgomes/bravent-todo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bravent Todo ✔

This is a Javascript todo app developed with Bravent. The goal of this project is to demonstrate the usage of the library to build applications based on Event Sourcing.

Running

  1. Ensure Node.js is installed (v6.0.0 should work);
  2. $ npm install
  3. $ npm start

API

Add a new todo item

Request:

$ curl localhost:3000/commands -X POST \
  --data '{"type": "addTodo", "text": "wash dishes"}' \
  -H 'Content-Type:application/json'

Response:

[{
  "type": "todoAdded",
  "id": "cf373798-efbc-4219-8fb3-e10d4c505a0b",
  "text": "wash dishes",
  "timestamp": "2016-09-08T01:47:00.490+0000"
}]

Toggle a todo

Request:

$ curl localhost:3000/commands -X POST \
  --data '{"type": "toggleTodo", "id": "cf373798-efbc-4219-8fb3-e10d4c505a0b"}' \
  -H 'Content-Type:application/json'

Response:

[{
  "type": "todoToggled",
  "id": "c5cdc877-19da-48eb-99f3-983cde01379f",
  "timestamp": "2016-09-08T01:48:00.490+0000"
}]

See the todo list

Request:

$ curl localhost:3000/state 

Response:

{
  "todos": [
    {
      "id": "c5cdc877-19da-48eb-99f3-983cde01379f",
      "text": "wash dishes",
      "completed": true,
      "timestamp": "2016-09-08T01:47:00.490+0000"
    }
  ]
}

See the event history

Request:

$ curl localhost:3000/events 

Response:

[
  {
    "type": "todoAdded",
    "id": "cf373798-efbc-4219-8fb3-e10d4c505a0b",
    "text": "wash dishes",
    "timestamp": "2016-09-08T01:47:00.490+0000"
  },
  {
    "type": "todoToggled",
    "id": "c5cdc877-19da-48eb-99f3-983cde01379f",
    "timestamp": "2016-09-08T01:48:00.490+0000"
  }
]

The /command end-point accepts commands identified by the type property. (This is a variation of the approach described in this blog post.) As a result of a successful command request, new events are responded to the client. As the samples above show, there are two types of domain events in the app: todoAdded and todoToggled. Those event are used to reconstruct the current state of the app (the todo list).

License

Feel free to use this code as you please.

About

Javascript todo app developed with Bravent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published