Common libraries for writing services/applications.
A service is a routing layers that plugs in event handlers.
In each service, you map HTTP endpoints to corresponding event handlers.
- Overview of the Makefile commands:
$ make help
- Install dependencies:
$ make init
- Get into the shell:
$ pipenv shell
from flowers.api import Service
class PingPongService(Service):
# event handlers
ping = lambda event: (HTTPStatus.OK, "PONG")
hello = lambda event: (HTTPStatus.OK, "Hello world!", headers)
routes = [(["GET"], "/hello", hello), (["GET"], "/ping", ping)]
import logging
import json
from flowers.api import Service, Middleware
class AuthMiddleware(Middleware):
def process_event(self, event):
pass
class PingLoggingMiddleware(Middleware):
def process_event(self, event):
print(f"{self.service} ==> {json.dumps(event)}")
return event
class HelloWorldService(Service):
middlewares = (PingLoggingMiddleware, AuthMiddleware)
hello = lambda event: (HTTPStatus.OK, "Hello world!")
See tests
for more examples on how to use this.