예제 #1
0
def create_app():
    routes = aiohug.RouteTableDef()

    @routes.get("/number/{number}/")
    async def return_number(number: fields.Int()):
        return {"number": number}

    app = web.Application()
    app.add_routes(routes)

    return app
예제 #2
0
def create_app():
    routes = aiohug.RouteTableDef()

    @routes.get("/hello/")
    async def hello():
        return web.json_response(data={"msg": "Hello, world"})

    app = web.Application()
    app.add_routes(routes)

    return app
예제 #3
0
def create_app():
    routes = aiohug.RouteTableDef()

    @routes.get("/hello/{name}")
    async def hello(name):
        return web.Response(text=f"Hello, {name}")

    app = web.Application()
    app.add_routes(routes)

    return app
def create_app():
    routes = aiohug.RouteTableDef()

    @routes.get("/ping/")
    async def return_number():
        return 201, {"msg": "pong"}

    app = web.Application()
    app.add_routes(routes)

    return app
예제 #5
0
def create_app():
    routes = aiohug.RouteTableDef()

    @routes.get("/hello/")
    async def hello(name, count: int = 1):  # you don't need to cast arguments
        return web.Response(text=f"Hello, {name}\n" * count)

    app = web.Application()
    app.add_routes(routes)

    return app
def create_app():
    routes = aiohug.RouteTableDef()

    @routes.get("/get-from-redis")
    async def return_number(redis):
        return {"value": redis.get("value")}

    app = web.Application()
    _redis = MagicMock(get=lambda name: 5)

    app["redis"] = _redis
    app.add_routes(routes)

    return app
def create_app():
    routes = aiohug.RouteTableDef()

    class RequestSchema(Schema):
        name = fields.Str()
        count = fields.Int()

    @routes.get("/hello/")
    async def hello(body: RequestSchema):
        return web.Response(text=f"Hello, {body['name']}\n" * body["count"])

    app = web.Application()
    app.add_routes(routes)

    return app
예제 #8
0
import uuid

import aiohug
from aiohug.swagger.handlers import routes as swagger_routes
from aiohug import swagger
from aiohttp import web
from marshmallow import Schema, fields

routes = aiohug.RouteTableDef()


class RequestSchema(Schema):
    nickname = fields.String()
    first_name = fields.String()
    age = fields.Int()


class ResponseSchema(RequestSchema):
    id = fields.UUID()


@swagger.spec(tags=['user'])
@swagger.response(201, schema=ResponseSchema, description="User creation")
@swagger.response(409,  description="Conflict")
@routes.post("/users/")
async def create_user(body: RequestSchema) -> ResponseSchema:
    """
    http --json POST  http://localhost:8080/users/ nickname=test

    :param body:
    :return: