예제 #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)
예제 #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)
예제 #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)
예제 #4
0
def setup_application():
    from anillo.app import application
    from anillo.utils import chain
    from anillo.middlewares.params import get_params_middleware
    from anillo.middlewares.json import json_middleware
    from anillo.middlewares.default_headers import default_headers_middleware
    from router import router
    handler = chain(
        get_params_middleware,
        json_middleware,
        default_headers_middleware({}, {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Headers": "Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version".lower(),
        }),
        router
    )
    return application(handler)
예제 #5
0
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)
예제 #6
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)
예제 #7
0
from anillo.app import application
from anillo.handlers.routing import router, url
from anillo.http import Ok


def index(request):
    return Ok("Index")


def hello(request):
    return Ok("Hello World!")

urls = [
    url("/", index),
    url("/hello", hello, methods=["get"]),
]

app = application(router(urls))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
예제 #8
0
파일: example.py 프로젝트: hirunatan/anillo
from anillo.app import application
from anillo.http import Ok


def index(request):
    return Ok("Hello World!")


app = application(index)

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
예제 #9
0
from anillo.app import application
from anillo.middlewares.json import json_middleware
from anillo.http import Ok


def index(request):
    return Ok({"echo-response": request.body["echo"]},
              headers={"Content-Type": "application/json"})


app = application(json_middleware(index))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
예제 #10
0
파일: example.py 프로젝트: hirunatan/anillo
from anillo.app import application
from anillo.http import Ok


def index(request):
    return Ok("Hello World!")


app = application(index)


if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
예제 #11
0
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)
예제 #12
0
from anillo.app import application
from anillo.utils import chain
from anillo.http import Ok
from anillo.middlewares.session import session_middleware, MemoryStorage
from anillo.middlewares.json import json_middleware
from anillo.middlewares.cookies import cookies_middleware


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(
        json_middleware,
        cookies_middleware,
        session_middleware(MemoryStorage()),
        index,
    ))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
예제 #13
0
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)
예제 #14
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)
예제 #15
0
    else:
        return NotFound()


def create(request):
    database.append(request.data)
    return Created(request.data, 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(json_middleware, router(urls)))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
예제 #16
0
from anillo.app import application
from anillo.middlewares.json import wrap_json
from anillo.http import Ok

#
# You can test this example with the curl line:
#
# curl -X POST -d '{"echo": "Hello World"}' localhost:5000 -H "Content-Type: application/json"
#

def index(request):
    return Ok({"echo-response": request.body["echo"]}, headers={"Content-Type": "application/json"})


app = application(wrap_json(index))


if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
예제 #17
0
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)