Middleware for every occasion
Project description
mediate
Middleware for every occasion
Installation
mediate
can be installed from PyPI
pip install mediate
Usage
@middleware
from mediate import middleware
def shout(call_next, name):
return call_next(name.upper())
def exclaim(call_next, name):
return call_next(name + "!")
@middleware(shout, exclaim)
def hello(name):
print(f"Hello, {name}")
>>> hello("sam")
Hello, SAM!
Middleware
Middleware.bind
import mediate
middleware = mediate.Middleware()
@middleware
def shout(call_next, name):
return call_next(name.upper())
@middleware
def exclaim(call_next, name):
return call_next(name + "!")
@middleware.bind
def hello(name):
print(f"Hello, {name}")
>>> hello("sam")
Hello, SAM!
Middleware.compose
import mediate
middleware = mediate.Middleware()
@middleware
def shout(call_next, name):
return call_next(name.upper())
@middleware
def exclaim(call_next, name):
return call_next(name + "!")
def hello(name):
print(f"Hello, {name}")
composed_hello = middleware.compose(hello)
>>> hello("sam")
Hello, sam
>>> composed_hello("sam")
Hello, SAM!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mediate-0.1.7.tar.gz
(3.4 kB
view hashes)