예제 #1
0
# -*- coding: utf-8 -*-
from aiorest_ws.app import Application
from aiorest_ws.command_line import CommandLine
from aiorest_ws.routers import SimpleRouter

from app.urls import router

main_router = SimpleRouter()
main_router.include(router)

if __name__ == '__main__':
    cmd = CommandLine()
    cmd.define('-ip', default='127.0.0.1', help='used ip', type=str)
    cmd.define('-port', default=8080, help='listened port', type=int)
    args = cmd.parse_command_line()

    app = Application()
    app.run(host=args.ip, port=args.port, router=main_router)
예제 #2
0
파일: server.py 프로젝트: Gipzo/aiorest-ws

class HelloWorldCustom(MethodBasedView):
    def get(self, request, user, id, *args, **kwargs):
        return "Hello, {0} with ID={1}".format(user, id)


class CalculateSum(MethodBasedView):
    def get(self, request, *args, **kwargs):
        try:
            digits = kwargs['params']['digits']
        except KeyError:
            digits = [0, ]
        return {"sum": sum(digits)}


router = SimpleRouter()
router.register('/hello', HelloWorld, 'GET')
router.register('/hello/{user}/{id}', HelloWorldCustom, 'GET')
router.register('/calc/sum', CalculateSum, 'GET')


if __name__ == '__main__':
    cmd = CommandLine()
    cmd.define('-ip', default='127.0.0.1', help='used ip', type=str)
    cmd.define('-port', default=8080, help='listened port', type=int)
    args = cmd.parse_command_line()

    app = Application()
    app.run(host=args.ip, port=args.port, router=router)
예제 #3
0
def default_command_line():
    cmd = CommandLine()
    clear_command_line(cmd)
    cmd.define('-ip', default='127.0.0.1', help='used ip', type=str)
    cmd.define('-port', default=8080, help='listened port', type=int)
    return cmd
예제 #4
0
def default_command_line():
    cmd = CommandLine()
    clear_command_line(cmd)
    cmd.define('-ip', default='127.0.0.1', help='used ip', type=str)
    cmd.define('-port', default=8080, help='listened port', type=int)
    return cmd