Server with HTTP API to manage events and consumer offsets
POST /api/v1/streams/<streamName>/events
--
HEADERS:
Accept: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
Authorization: Basic <base64>
X-Producer-ID: <producerID>
--
BODY:
{
"event": {
"name" : "OrderPlaced",
"version" : 1
},
"system" : {
"id" : "alv123",
"name" :"codello alvine",
"time": "2017-09-06 13:58:12",
"timezone" : "Europe/Berlin"
},
"trigger" : {
"type": "system",
"name": "/path/to/script.php"
},
"payload" : {}
}
Possible responses:
All responses should send the header Content-Type: application/json; charset=utf-8
.
HTTP code | Output | Comment |
---|---|---|
200 | "" | The newly created event ID |
423 | "Locked - Second writers not allowed" | A producer tries to write to a stream of another producer |
401 | "Unauthorized" | Invalid credentials |
400 | "Bad Request - " | Error if the request is malformed |
500 | "Internal Server Error - " | Any other error |
GET /api/v1/streams/<streamName>/events
--
PARAMETERS:
eventName=[string] (mandatory)
limit=[int] (mandatory)
--
HEADERS:
Accept: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
Authorization: Basic <base64>
X-Consumer-ID: <consumerID>
Possible responses:
All responses should send the header Content-Type: application/json; charset=utf-8
.
HTTP code | Output | Comment |
---|---|---|
200 | array of JSON events |
A list of events from the requested stream |
401 | "Unauthorized" | Invalid credentials |
404 | "Not Found[ - ]" | Error if the stream was not found |
400 | "Bad Request - " | Error if the request is malformed |
500 | "Internal Server Error - " | Any other error |
POST /api/v1/streams/<streamName>/events/<eventID>
--
HEADERS:
Accept: application/json; charset=utf-8
Content-Type: application/x-www-form-urlencoded
Authorization: Basic <base64>
X-Consumer-ID: <consumerID>
--
BODY:
action=ACK
Possible responses:
All responses should send the header Content-Type: application/json; charset=utf-8
.
HTTP code | Output | Comment |
---|---|---|
200 | "OK" | Acknowledgement received |
401 | "Unauthorized" | Invalid credentials |
404 | "Not Found" | Error if the stream or event ID was not found |
400 | "Bad Request - " | Error if the request is malformed |
500 | "Internal Server Error - " | Any other error |
- Create new read/write route and corresponding request handler.
- Implement the PreAuthenticatesToken interface in the request handler
- Now the route can be called with valid credentials (basic auth) only. Otherwise the unauthorized response will be returned.
- In case you don't want the route to be secured, just create request handler without implementing the PreAuthenticatesToken interface
docker-composer up -d
This will automatically:
- Build all necessary docker images for
python
andpostgres
docker-compose run --rm backend pipenv install -d
docker-compose run --rm backend pipenv run python -m unittest discover tests/unit/ -v
This will execute all unit tests.
Alternatively the Makefile could be used for executing some tasks locally. Type "make" or "make help" in the root directory, this will display all available make tasks. There is no guarantee this would work on WinOS. So, probably you need to install some tool to be able to run the tasks on WinOS.
make help