Function signature
The Python function receives two arguments: body and req.
def handler(body, req):
...
body
The HTTP request data as a Pythoic object. The raw data is deserialized as JSON.
Code
def handler(body, req):
return 'body: {}'.format(body)
Invocation
$ bn invoke signature --data '{"a": "b"}'
"body: {u'a': u'b'}"
$ curl -d '{"a": "b"}' -H X-Binaris-Api-Key:$(bn show apiKey) https://run.binaris.com/v2/run/$(bn show accountId)/signature
"body: {u'a': u'b'}"
$ curl -d '"Quoted string"' -H X-Binaris-Api-Key:$(bn show apiKey) https://run.binaris.com/v2/run/$(bn show accountId)/signature
"body: Quoted string"
$ curl -d '[1, 2, 3, 4, 5]' -H X-Binaris-Api-Key:$(bn show apiKey) https://run.binaris.com/v2/run/$(bn show accountId)/signature
"body: [1, 2, 3, 4, 5]"
Request
The Request object exposes raw HTTP data to the developer.
method
Exposes the HTTP Method of the request.
Code
def handler(body, req):
return 'method: {}'.format(req.method)
Invocation
$ bn invoke signature
"body: POST"
$ curl -H X-Binaris-Api-Key:$(bn show apiKey) https://run.binaris.com/v2/run/$(bn show accountId)/signature
"body: GET"
path
Exposes the path part of the URL after the function name.
Code
def handler(body, req):
return 'path: {}'.format(req.path)
Invocation
$ bn invoke signature
"path: /"
$ curl -H X-Binaris-Api-Key:$(bn show apiKey) https://run.binaris.com/v2/run/$(bn show accountId)/signature/p/a/t/h
"path: /p/a/t/h"
version
Exposes the HTTP version of the request.
Code
def handler(body, req):
return 'version: {}'.format(req.version)
Invocation
$ bn invoke signature
"version: HTTP/1.1"
remote_ip
Exposes the IP of the caller.
Code
def handler(body, req):
return 'remote_ip: {}'.format(req.remote_ip)
Invocation
$ bn invoke signature
"remote_ip: 172.126.13.148"
query
Code
def handler(body, req):
return 'query: {}'.format(req.query)
Invocation
$ bn invoke signature
"query: {}"
$ curl -H X-Binaris-Api-Key:$(bn show apiKey) https://run.binaris.com/v2/run/$(bn show accountId)/signature?Unladen=Swallow
"query: {'Unladen': 'Swallow'}"
headers
Exposes the HTTP request headers.
Code
def handler(body, req):
return 'headers: {}'.format(req.headers.items())
Invocation
$ bn invoke signature
"headers: [('Content-Type', 'application/json'),
('Host', 'backend'),
('Content-Length', '0'),
('X-Binaris-Request-Id', '11783ba72bc4a1e5439bd0dd9ae15023')]"
$ curl -H Emmental:Brie -H X-Binaris-Api-Key:$(bn show apiKey) https://run.binaris.com/v2/run/$(bn show accountId)/signature
"headers: [('Emmental', 'Brie'),
('Host', 'backend'),
('X-Binaris-Request-Id', '031862caf4c46d914f95a8c9df82bee6'),
('Accept', '*/*'),
('User-Agent', 'curl/7.54.0')]"
request.body
Alias for body.