How to use the blacksheep.JsonContent function in blacksheep

To help you get started, we’ve selected a few blacksheep 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 RobertoPrevato / BlackSheep / tests / test_application.py View on Github external
async def example(request):
        nonlocal calls
        calls.append(5)
        return Response(200,
                        [(b'Server', b'Python/3.7')],
                        JsonContent({'id': '123'}))
github RobertoPrevato / BlackSheep / tests / test_bindings.py View on Github external
async def test_from_body_json_binding_extra_parameters_strategy():

    request = Request('POST', b'/', [
        JsonContentType
    ]).with_content(JsonContent({
        'a': 'world',
        'b': 9000,
        'c': 'This is an extra parameter, accepted by constructor explicitly'
    }))

    parameter = FromJson(ExampleTwo)

    value = await parameter.get_value(request)

    assert isinstance(value, ExampleTwo)
    assert value.a == 'world'
    assert value.b == 9000
github RobertoPrevato / BlackSheep / blacksheep / server / responses.py View on Github external
def status_code(status: int = 200, message: MessageType = None):
    """Returns a plain response with given status, with optional message; sent as plain text or JSON."""
    if not message:
        return Response(status)
    if isinstance(message, str):
        content = TextContent(message)
    else:
        content = JsonContent(message)
    return Response(status, content=content)
github RobertoPrevato / BlackSheep / blacksheep / server / responses.py View on Github external
def created(location: BytesOrStr, value: Any = None):
    """Returns an HTTP 201 Created response, to the given location and with optional JSON content."""
    return Response(201,
                    [(b'Location', _ensure_bytes(location))],
                    JsonContent(value) if value else None)