Skip to content

Server with HTTP API to manage events and consumer offsets

Notifications You must be signed in to change notification settings

pavbis/python-eventserver

Repository files navigation

Python / Event server

Description

Server with HTTP API to manage events and consumer offsets

API

Receiving an event for a specific stream

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

Providing events from a specific stream for consumption

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

Receive an acknowledgement after an event consumption

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

Authorisation

  • 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

Local development

Bring up the environment

docker-composer up -d

This will automatically:

  • Build all necessary docker images for python and postgres

Install dependencies

docker-compose run --rm backend pipenv install -d

Run tests

docker-compose run --rm backend pipenv run python -m unittest discover tests/unit/ -v

This will execute all unit tests.

Using Makefile

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

alt text

About

Server with HTTP API to manage events and consumer offsets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published