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.

Example

Code
def handler(body, req):
    return 'body: {}'.format(body)
Invocation
$ bn invoke signature --data '{"a": "b"}'
"body: {u'a': u'b'}"

$ curl 'https://run.binaris.com/v1/run/<key>/signature' -d '{"a": "b"}'
"body: {u'a': u'b'}"

$ curl 'https://run.binaris.com/v1/run/<key>/signature' -d '"Quoted string"'
"body: Quoted string"

$ curl 'https://run.binaris.com/v1/run/<key>/signature' -d '[1, 2, 3, 4, 5]'
"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 'https://run.binaris.com/v1/run/<key>/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 'https://run.binaris.com/v1/run/<key>/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 'https://run.binaris.com/v1/run/<key>/signature?Unlade=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' 'https://run.binaris.com/v1/run/<key>/signature'
"headers: [('Emmental', 'Brie'),
           ('Host', 'backend'),
           ('X-Binaris-Request-Id', '031862caf4c46d914f95a8c9df82bee6'),
           ('Accept', '*/*'),
           ('User-Agent', 'curl/7.54.0')]"

request.body

Alias for body.