How to use the fdk.response 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 / fdk / json / handle.py View on Github external
: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,
            status_code=200,
        )
github fnproject / fdk-python / fdk / http / 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):
        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:
github fnproject / fdk-python / fdk / http / handle.py View on Github external
@response.safe
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):
github fnproject / fdk-python / fdk / http / handle.py View on Github external
: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))