Beispiel #1
0
def setup_application():
    import settings

    from anillo.app import application
    from anillo.utils.common import chain
    from anillo.middlewares.json import wrap_json_body, wrap_json_response
    from anillo.middlewares.cors import wrap_cors, DEFAULT_HEADERS
    from anillo.middlewares.default_headers import wrap_default_headers
    from anillo.middlewares.params import wrap_query_params
    from anillo_auth.auth import wrap_auth
    from anillo_auth.backends.token import JWSBackend
    from .middlewares import wrap_verify_user, wrap_error_handler

    from tools.camelize.middlewares import wrap_camelize_response_body
    from tools.camelize.middlewares import wrap_underscoreize_request_body

    from .router import router

    handler = chain(
        wrap_cors(allow_headers=list(DEFAULT_HEADERS) + ["x-session-id", "accept-language", "authorization"]),
        wrap_error_handler,
        wrap_auth(backend=lambda: JWSBackend(secret=settings.SECRET_KEY, token_name="Bearer")),
        wrap_verify_user,
        wrap_json_body(),
        wrap_underscoreize_request_body,
        wrap_json_response,
        wrap_camelize_response_body,
        wrap_default_headers({}, {"Content-Type": "application/json"}),
        wrap_query_params,
        router
    )

    return application(handler)
Beispiel #2
0
def setup_anillo_app():
    from anillo.app import application
    from anillo.utils.common import chain
    from anillo.middlewares.json import wrap_json_body, wrap_json_response
    from anillo.middlewares.cors import wrap_cors, DEFAULT_HEADERS
    from anillo.middlewares.default_headers import wrap_default_headers
    from anillo.middlewares.params import wrap_query_params
    # from .middlewares import wrap_error_handler

    from tools.camelize.middlewares import wrap_camelize_response_body
    from tools.camelize.middlewares import wrap_underscoreize_request_body

    from .router import router

    handler = chain(
        wrap_cors(allow_headers=list(DEFAULT_HEADERS) +
                  ["x-session-id", "accept-language", "authorization"]),
        # wrap_error_handler,
        wrap_json_body(),
        wrap_underscoreize_request_body,
        wrap_json_response,
        wrap_camelize_response_body,
        wrap_default_headers({}, {"Content-Type": "application/json"}),
        wrap_query_params,
        router)

    return application(handler)
Beispiel #3
0
def setup_app():
    main_handler = chain(
            wrap_auth(backend=auth_backend),
            wrap_json_body,
            wrap_json_response,
            wrap_cors_response,
            wrap_sqlalchemy_session,
            router(urls)
    )

    return application(main_handler)
from anillo.app import application
from anillo.utils.common import chain
from anillo.http import Ok


def middleware(func):
    def wrapper(request):
        request.new_data = "Middleware data"
        return func(request)
    return wrapper


def index(request):
    return Ok(request.new_data)


app = application(chain(middleware, index))


if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
Beispiel #5
0
        return NotFound()


def create(request):
    database.append(request.body)
    return Created(request.body, mimetype="application/json")


def delete(request, index):
    if len(database) > index:
        del database[index]
        return NoContent()
    else:
        return NotFound()


urls = [
    context("/api", [
        url("/", list, methods=["get"]),
        url("/", create, methods=["post"]),
        url("/<int:index>", detail, methods=["get"]),
        url("/<int:index>", delete, methods=["delete"]),
    ])
]

app = application(chain(wrap_json, router(urls)))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
from anillo.app import application
from anillo.utils.common import chain
from anillo.http import Ok
from anillo.middlewares.session import wrap_session, MemoryStorage
from anillo.middlewares.json import wrap_json
from anillo.middlewares.cookies import wrap_cookies


def index(request):
    value = request.session.get('value', 0)
    request.session['value'] = value + 1
    return Ok(request.session, headers={"Content-Type": "application/json"})


app = application(chain(
    wrap_json,
    wrap_cookies,
    wrap_session(storage=MemoryStorage),
    index,
))


if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
from anillo.app import application
from anillo.utils.common import chain
from anillo.http import Ok
from anillo.middlewares.session import wrap_session, MemoryStorage
from anillo.middlewares.json import wrap_json
from anillo.middlewares.cookies import wrap_cookies


def index(request):
    value = request.session.get('value', 0)
    request.session['value'] = value + 1
    return Ok(request.session, headers={"Content-Type": "application/json"})


app = application(
    chain(
        wrap_json,
        wrap_cookies,
        wrap_session(storage=MemoryStorage),
        index,
    ))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
Beispiel #8
0
    else:
        return NotFound()


def create(request):
    database.append(request.body)
    return Created(request.body, mimetype="application/json")


def delete(request, index):
    if len(database) > index:
        del database[index]
        return NoContent()
    else:
        return NotFound()

urls = [
    context("/api", [
        url("/", list, methods=["get"]),
        url("/", create, methods=["post"]),
        url("/<int:index>", detail, methods=["get"]),
        url("/<int:index>", delete, methods=["delete"]),
    ])
]

app = application(chain(wrap_json, router(urls)))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
from anillo.app import application
from anillo.utils.common import chain
from anillo.http import Ok


def middleware(func):
    def wrapper(request):
        request.new_data = "Middleware data"
        return func(request)

    return wrapper


def index(request):
    return Ok(request.new_data)


app = application(chain(middleware, index))


if __name__ == "__main__":
    from anillo import serving

    serving.run_simple(app, port=5000)