How to use the fdk.response.RawResponse function in fdk

To help you get started, we’ve selected a few fdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fnproject / fdk-python / samples / hot / http / custom-response / func.py View on Github external
def app(context, data=None, loop=None):
    """
    This is just an echo function
    :param context: request context
    :type context: hotfn.http.request.RequestContext
    :param data: request body
    :type data: object
    :param loop: asyncio event loop
    :type loop: asyncio.AbstractEventLoop
    :return: echo of request body
    :rtype: object
    """
    headers = {
        "Content-Type": "plain/text",
    }
    rs = response.RawResponse(
        context,
        status_code=200,
        headers=headers,
        response_data="OK")
    return rs
github fnproject / fdk-python / samples / hot / http / async-echo / func.py View on Github external
async def app(context, data=None, loop=None):
    """
    This is just an echo function
    :param context: request context
    :type context: fdk.context.RequestContext
    :param data: request body
    :type data: object
    :param loop: asyncio event loop
    :type loop: asyncio.AbstractEventLoop
    :return: echo of request body
    :rtype: object
    """
    headers = {
        "Content-Type": "plain/text",
    }
    return response.RawResponse(
        context,
        status_code=200,
        headers=headers,
        response_data="OK")
github fnproject / fdk-python / fdk / json / handle.py View on Github external
def normal_dispatch(app, context, data=None, loop=None):
    """
    Request handler app dispatcher
    :param app: request handler app
    :type app: types.Callable
    :param context: request context
    :type context: request.RequestContext
    :param data: request body
    :type data: io.BufferedIOBase
    :param loop: asyncio event loop
    :type loop: asyncio.AbstractEventLoop
    :return: raw response
    :rtype: response.RawResponse
    """
    rs = app(context, data=data, loop=loop)
    if isinstance(rs, response.RawResponse):
        return rs
    elif isinstance(rs, types.CoroutineType):
        return loop.run_until_complete(rs)
    elif isinstance(rs, str):
        hs = headers.GoLikeHeaders({})
        hs.set('content-type', 'text/plain')
        return response.RawResponse(context, response_data=rs)
    elif isinstance(rs, bytes):
        hs = headers.GoLikeHeaders({})
        hs.set('content-type', 'application/octet-stream')
        return response.RawResponse(
            context,
            response_data=rs.decode("utf8"),
            headers=hs,
            status_code=200
        )
github fnproject / fdk-python / fdk / http / handle.py View on Github external
elif isinstance(rs, types.CoroutineType):
        return loop.run_until_complete(rs)
    elif isinstance(rs, str):
        return response.RawResponse(
            context,
            status_code=200,
            headers={},
            response_data=rs)
    elif isinstance(rs, bytes):
        return response.RawResponse(
            context,
            status_code=200,
            headers={'content-type': 'application/octet-stream'},
            response_data=rs.decode("utf8"))
    else:
        return response.RawResponse(
            context,
            status_code=200,
            headers={'content-type': 'application/json'},
            response_data=ujson.dumps(rs))
github fnproject / fdk-python / samples / python3-fn-gpi / func.py View on Github external
action_kwargs["dependencies"] = dependencies

    log.log("cached dependencies unpickled")

    try:
        res = action(*action_args, **action_kwargs)
    except Exception as ex:
        log.log("call failed")
        return response.RawResponse(
            ctx,
            status_code=500,
            response_data=str(ex))

    log.log("call result: {}".format(res))

    return response.RawResponse(
        ctx,
        status_code=200,
        response_data=res)
github fnproject / fdk-python / fdk / json / handle.py View on Github external
:param data: request body
    :type data: io.BufferedIOBase
    :param loop: asyncio event loop
    :type loop: asyncio.AbstractEventLoop
    :return: raw response
    :rtype: response.RawResponse
    """
    rs = app(context, data=data, loop=loop)
    if isinstance(rs, response.RawResponse):
        return rs
    elif isinstance(rs, types.CoroutineType):
        return loop.run_until_complete(rs)
    elif isinstance(rs, str):
        hs = headers.GoLikeHeaders({})
        hs.set('content-type', 'text/plain')
        return response.RawResponse(context, response_data=rs)
    elif isinstance(rs, bytes):
        hs = headers.GoLikeHeaders({})
        hs.set('content-type', 'application/octet-stream')
        return response.RawResponse(
            context,
            response_data=rs.decode("utf8"),
            headers=hs,
            status_code=200
        )
    else:
        hs = headers.GoLikeHeaders({})
        hs.set('content-type', 'application/json')
        return response.RawResponse(
            context,
            response_data=ujson.dumps(rs),
            headers=hs,
github fnproject / fdk-python / fdk / http / handle.py View on Github external
:param context: request context
    :type context: request.RequestContext
    :param data: request body
    :type data: io.BufferedIOBase
    :param loop: asyncio event loop
    :type loop: asyncio.AbstractEventLoop
    :return: raw response
    :rtype: response.RawResponse
    """
    rs = app(context, data=data, loop=loop)
    if isinstance(rs, response.RawResponse):
        return rs
    elif isinstance(rs, types.CoroutineType):
        return loop.run_until_complete(rs)
    elif isinstance(rs, str):
        return response.RawResponse(
            context,
            status_code=200,
            headers={},
            response_data=rs)
    elif isinstance(rs, bytes):
        return response.RawResponse(
            context,
            status_code=200,
            headers={'content-type': 'application/octet-stream'},
            response_data=rs.decode("utf8"))
    else:
        return response.RawResponse(
            context,
            status_code=200,
            headers={'content-type': 'application/json'},
            response_data=ujson.dumps(rs))