How to use the aiohttp.web.json_response function in aiohttp

To help you get started, we’ve selected a few aiohttp 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 FAForever / server / tests / unit_tests / test_lobbyconnection.py View on Github external
async def token(request):
        data = await request.json()
        return web.json_response({'result': data.get('uid_hash')})
github molior-dbs / molior / molior / api / build.py View on Github external
request.cirrina.db_session.add(build)
    request.cirrina.db_session.commit()
    await build.build_added()

    token = uuid.uuid4()
    buildtask = BuildTask(build=build, task_id=str(token))
    request.cirrina.db_session.add(buildtask)
    request.cirrina.db_session.commit()

    if git_ref == "":
        args = {"buildlatest": [repo.id, build.id]}
    else:
        args = {"build": [build.id, repo.id, git_ref, git_branch]}
    await request.cirrina.task_queue.put(args)

    return web.json_response({"build_token": str(token)})
github playpauseandstop / rororo / examples / petstore / views.py View on Github external
async def create_pet(request: web.Request) -> web.Response:
    with openapi_context(request) as context:
        new_pet = NewPet(
            name=context.data["name"], tag=context.data.get("tag")
        )

        pet = new_pet.to_pet(len(request.app["pets"]) + 1)
        request.app["pets"].append(pet)

    return web.json_response(attr.asdict(pet))
github mozilla / PollBot / pollbot / views / release.py View on Github external
async def wrapped(request, product, version):
        try:
            response = await task(product, version)
        except Exception as e:  # In case something went bad, we return an error status message
            logger.exception(e)
            body = {
                'status': 'error',
                'message': str(e)
            }
            if hasattr(e, 'url') and e.url is not None:
                body['link'] = e.url

            return web.json_response(body)
        return web.json_response(response)
    return wrapped
github tartiflette / tartiflette-aiohttp / tartiflette_aiohttp / _handler.py View on Github external
def prepare_response(data):
    headers = {}
    # TODO Do things with header here
    return web.json_response(data, headers=headers, dumps=json.dumps)
github aio-libs / aiozipkin / examples / microservices / service_e.py View on Github external
async def handler(request):
    await asyncio.sleep(0.01)
    payload = {'name': 'service_e', 'host': host, 'port': port, 'children': []}
    return web.json_response(payload)
github facebook / openbmc / meta-facebook / meta-wedge400 / recipes-utils / rest-api / files / board_endpoint.py View on Github external
async def rest_feutil_fan4_hdl(self, request):
        return web.json_response(
            rest_feutil.get_feutil_fan4_data(), dumps=dumps_bytestr
        )
github hyperledger / aries-cloudagent-python / aries_cloudagent / protocols / out_of_band / v1_0 / routes.py View on Github external
include_handshake = body.get("include_handshake")
    use_public_did = body.get("use_public_did")
    multi_use = json.loads(request.query.get("multi_use", "false"))
    oob_mgr = OutOfBandManager(context)

    try:
        invitation = await oob_mgr.create_invitation(
            multi_use=multi_use,
            attachments=attachments,
            include_handshake=include_handshake,
            use_public_did=use_public_did,
        )
    except (StorageNotFoundError, ValidationError, OutOfBandManagerError) as e:
        raise web.HTTPBadRequest(reason=str(e))

    return web.json_response(invitation.serialize())
github CityOfZion / neo-python / neo / api / utils.py View on Github external
async def wrapper(self, request, *args, **kwargs):
        res = await func(self, request, *args, **kwargs)
        response = web.json_response(data=res)
        if response.content_length > COMPRESS_THRESHOLD:
            response.enable_compress(force=ContentCoding.gzip)
        return response
github bmartin5692 / bumper / bumper / confserver.py View on Github external
service = postbody["service"]
                if service == "EcoMsgNew":
                    srvip = bumper.bumper_announce_ip
                    srvport = 5223
                    confserverlog.info(
                        "Announcing EcoMsgNew Server to bot as: {}:{}".format(
                            srvip, srvport
                        )
                    )
                    msgserver = {"ip": srvip, "port": srvport, "result": "ok"}
                    msgserver = json.dumps(msgserver)
                    msgserver = msgserver.replace(
                        " ", ""
                    )  # bot seems to be very picky about having no spaces, only way was with text

                    return web.json_response(text=msgserver)

                elif service == "EcoUpdate":
                    srvip = "47.88.66.164"  # EcoVacs Server
                    srvport = 8005
                    confserverlog.info(
                        "Announcing EcoUpdate Server to bot as: {}:{}".format(
                            srvip, srvport
                        )
                    )
                    body = {"result": "ok", "ip": srvip, "port": srvport}

            return web.json_response(body)

        except Exception as e:
            confserverlog.exception("{}".format(e))