示例#1
0

def handler4(request, id):
    return Response("test4 - {}".format(id))


class TestRequest(Request):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.server_name = "test"
        self.server_port = "80"
        self.scheme = "http"


urls = [
    url("/", handler1, methods=["get", "post"], name="handler1"),
    url("/<int:id>", handler2, methods="get", name="handler2"),
    context(
        "/test",
        [
            url("/", handler3, methods=["get", "post"], name="handler3"),
            url("/<int:id>", handler4, methods=["get", "post"], name="handler4"),
        ],
    ),
]

app = router(urls)


def test_routing_root():
    request = TestRequest(uri="/", method="get")
示例#2
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)
示例#3
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)
示例#4
0
from anillo.handlers.routing import optionized_url as url, context


from controllers.index import Index
from controllers.user import Login, Register, List
from controllers.computer import ComputerList, ComputerMethods
from controllers.program import ProgramList, ProgramMethods

urls = [
    context("/api/v1", [
        url("/", Index(), methods=["get", "post"]),
        url("/login", Login(), methods=["post"]),
        url("/users", Register(), methods=["post"]),
        url("/users", List(), methods=["get"]),
        url("/computer", ComputerMethods(), methods=["get", "post", "put", "delete"]),
        url("/computers", ComputerList(), methods=["get"]),
        url("/program", ProgramMethods(), methods=["get", "post", "put", "delete"]),
        url("/programs", ProgramList(), methods=["get"]),
    ]),
]
示例#5
0

def handler4(request, id):
    return Response("test4 - {}".format(id))


class TestRequest(Request):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.server_name = "test"
        self.server_port = "80"
        self.scheme = "http"


urls = [
    url("/", handler1, methods=["get", "post"], name="handler1"),
    url("/<int:id>", handler2, methods="get", name="handler2"),
    context("/test", [
        url("/", handler3, methods=["get", "post"], name="handler3"),
        url("/<int:id>", handler4, methods=["get", "post"], name="handler4"),
    ])
]

app = router(urls)


def test_routing_root():
    request = TestRequest(uri="/", method="get")
    response = app(request)
    assert response.body == "test1"
示例#6
0
from anillo.handlers.routing import optionized_url as url, context


from controllers.index import Index
from controllers.user import Login, Register, List

urls = [
    context("/api/v1", [
        url("/", Index(), methods=["get", "post"]),
        url("/login", Login(), methods=["post"]),
        url("/users", Register(), methods=["post"]),
        url("/users", List(), methods=["get"]),
    ]),
]
示例#7
0
from anillo.handlers.routing import optionized_url as url, context


from controllers.index import Index
from controllers.user import Login, Register, List
from controllers.author import ListCreateAuthors, DetailUpdateDeleteAuthor
from controllers.book import CreateListBook, DetailUpdateDeleteBook, ListCreateTag, DetailTag
from controllers.stock import GetStock, PeDetails, ListStocks

urls = [
    context("/api/v1", [
        url("/", Index(), methods=["get", "post"]),
        url("/login", Login(), methods=["post"]),
        url("/users", Register(), methods=["post"]),
        url("/users", List(), methods=["get"]),
        url("/authors", ListCreateAuthors(), methods=["get", "post"]),
        url("/authors/<int:pk>", DetailUpdateDeleteAuthor(), methods=["get", "delete", "put"]),
        url("/books", CreateListBook(), methods=["get", "post"]),
        url("/books/<int:pk>", DetailUpdateDeleteBook(), methods=["get", "delete", "put"]),
        url("/tags", ListCreateTag(), methods=["get", "post"]),
        url("/tags/<int:pk>", DetailTag(), methods=["get"]),
        url("/stocks", ListStocks(), methods=["get"]),
        url("/stocks/<int:pk>", GetStock(), methods=["get"]),
        url("/stocks/pe-info", PeDetails(), methods=["get"]),

    ]),
]
示例#8
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),
]

app = application(router(urls))

if __name__ == '__main__':
    from anillo import serving
    serving.run_simple(app, port=5000)
示例#9
0
文件: urls.py 项目: zenx/api-example
from anillo.handlers.routing import optionized_url as url, context


from controllers.index import Index
from controllers import user, artist

urls = [
    context("/api/v1", [
        url("/", Index(), methods=["get", "post"]),

        # user urls
        url("/login", user.Login(), methods=["post"]),
        url("/users", user.Register(), methods=["post"]),
        url("/users", user.List(), methods=["get"]),

        # artist urls
        url("/artists", artist.List(), methods=["get"]),
        url("/artists", artist.Create(), methods=["post"]),
        url("/artists/<int:id>", artist.Update(), methods=["put"]),
        url("/artists/<int:id>", artist.Delete(), methods=["delete"]),
        url("/artists/<int:id>", artist.Get(), methods=["get"]),
        url("/artists/<int:id>/like", artist.Like(), methods=["post"]),
        url("/artists/<int:id>/unlike", artist.Unlike(), methods=["post"]),
    ]),
]
示例#10
0

def handler4(request, id):
    return Response("test4 - {}".format(id))


class TestRequest(Request):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.server_name = "test"
        self.server_port = "80"
        self.scheme = "http"


urls = [
    url("/", handler1, methods=["get", "post"]),
    url("/<int:id>", handler2, methods="get"),
    context("/test", [
        url("/", handler3, methods=["get", "post"]),
        url("/<int:id>", handler4, methods=["get", "post"]),
    ])
]

app = router(urls)


def test_routing_root():
    request = TestRequest(uri="/", method="get")
    response = app(request)
    assert response.body == "test1"
示例#11
0
from endpoints.web.api.assessments import assessment_handlers, form_handlers, topic_handlers
from endpoints.web.api.organizations import organization_handlers

PREFIX = "/api/v1"

urls = [
    # User
    # url(PREFIX + "/login", user_handlers.Login(), methods=["post"]),
    # url(PREFIX + "/logout", user_handlers.Logout(), methods=["post"]),
    # url(PREFIX + "/users", user_handlers.UsersList(), methods=["get"]),
    # url(PREFIX + "/users/<string:username>", user_handlers.UserDetail(), methods=["get", "patch", "delete"]),

    # Assessments
    url(PREFIX + "/assessments",
        assessment_handlers.AssessmentsList(),
        methods=["get"]),
    url(PREFIX + "/assessments/<string:assessment_id>",
        assessment_handlers.AssessmentDetail(),
        methods=["get"]),
    url(PREFIX + "/assessments/<string:assessment_id>/stakeholders",
        assessment_handlers.AssessmentStakeholdersList(),
        methods=["get"]),
    url(PREFIX + "/assessments/<string:assessment_id>/forms",
        form_handlers.AssessmentFormsList(),
        methods=["get"]),
    url(PREFIX + "/assessments/<string:assessment_id>/forms/<string:form_id>",
        form_handlers.AssessmentFormDetail(),
        methods=["get"]),
    url(PREFIX + "/assessments/<string:assessment_id>/topics",
        topic_handlers.AssessmentTopicsList(),
示例#12
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)
示例#13
0
import os.path

from anillo.handlers.routing import router as anillo_router, optionized_url as url
from anillo.http import responses

from web.api.users import user_handlers
from web.api.ideas import idea_handlers
from web.api.projects import project_handlers

PREFIX = "/api/v1"

urls = [
    # User
    url(PREFIX + "/login", user_handlers.Login(), methods=["post"]),
    url(PREFIX + "/logout", user_handlers.Logout(), methods=["post"]),
    url(PREFIX + "/users", user_handlers.UsersList(), methods=["get"]),
    url(PREFIX + "/users/<string:username>", user_handlers.UserDetail(), methods=["get", "patch", "delete"]),

    # Ideas
    url(PREFIX + "/ideas",
        idea_handlers.IdeasList(), methods=["get", "post"]),
    url(PREFIX + "/ideas/<string:idea_uuid>",
        idea_handlers.IdeaDetail(), methods=["get", "patch", "delete"]),
    url(PREFIX + "/ideas/<string:idea_uuid>/invited",
        idea_handlers.IdeaInvitedList(), methods=["get", "post", "delete"]),
    url(PREFIX + "/ideas/<string:idea_uuid>/comments",
        idea_handlers.IdeaCommentsList(), methods=["get", "post", "delete"]),
    url(PREFIX + "/ideas/<string:idea_uuid>/reactions",
        idea_handlers.IdeaReactionsList(), methods=["get", "post", "delete"]),
    url(PREFIX + "/ideas/<string:idea_uuid>/fork",
        idea_handlers.IdeaFork(), methods=["post"]),
示例#14
0
# coding: utf-8

# third party
from anillo.handlers.routing import router as anillo_router, url

# guild empire back
import handlers


urls = [
    url("/api/v1/create_game", handlers.create_game, methods=["get"]),
    url("/api/v1/turn", handlers.get_turn, methods=["get"]),
    url("/api/v1/turn", handlers.post_turn, methods=["post"]),
]

router = anillo_router(urls)