Commit ac621b23 authored by Michał Góral's avatar Michał Góral

Updated README.

parent c7c58a0c
......@@ -5,9 +5,11 @@ writing and acting upon incoming webhooks.
Awh splits webhook handling into _validating_ and _executing_. You must register
both validator and executor to handle webhooks. These are simple functions which
accept a single request parameter containing incoming request data. Many
validators and executors (for many different webhooks) can be registered. Any
validator returning `True` marks webhook as correct.
accept a request parameter containing incoming request data. Additionaly they
receive a dictionary which is filled with arbitrary data by response manipulator
(a function decorated with `@app.app` decorator). Many validators and executors
(for many different webhooks) can be registered. Any validator returning `True`
marks webhook as correct.
You can also affect application's response by registering a separate function
accepting incoming request and to-be-modified response parameter.
......@@ -26,23 +28,25 @@ from awh.operate import require, jsonpath
app = Awh()
@app.validator('foo')
def valid(request):
def valid(request, data_dict):
payload = request.get_data(as_text=True)
j = json.loads(payload)
# validate incoming json somehow
require(jsonpath(j, 'password')[0].value == 'secretpass')
require(data_dict.get('foo') == 'bar')
return True
@app.executor('foo')
def execute(request):
def execute(request, data_dict):
subprocess.call('deploy-app')
@app.app
def myapp(request, response):
def myapp(request, response, data_dict):
response.status_code = 404
data_dict['foo'] == 'bar'
----
For additional examples, see link:tests/apps[tests/apps].
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment