Exemple #1
0
class Tickets(BaseView):
    """
        REST API Example

        GET /tickets - Retrieves a list of tickets
        GET /tickets/12 - Retrieves a specific ticket
        POST /tickets - Creates a new ticket
        PUT /tickets/12 - Updates ticket #12
        PATCH /tickets/12 - Partially updates ticket #12
        DELETE /tickets/12 - Deletes ticket #12
    """
    rule('/tickets', methods=['GET', 'POST'])
    rule('<int:ticket_id>', methods=['GET', 'PUT', 'PATCH', 'DELETE'])

    def get(self, ticket_id=None):
        if ticket_id:
            return 'single'
        return 'list'

    def post(self):
        return 'create'

    def put(self, ticket_id):
        return 'update'

    def patch(self, ticket_id):
        return 'partial update'

    def delete(self, ticket_id):
        return 'delete'
Exemple #2
0
class HWRuleDefault(BaseView):
    """
        GET /hwrd -> 'Hello RD'
        GET /hwrd/foo -> 'Hello Foo'
        POST /hwrd -> 'post Hello RD'
        POST /hwrd-> 'post Hello Foo'
    """
    # Since the default rule needs to have defaults, you need to define it and not rely on the
    # auto-generated one.
    rule('/hwrd', post=True, defaults={'name': 'RD'})
    rule('<name>', post=True)

    def post(self, name):
        return 'post Hello {}'.format(name)

    def get(self, name):
        return 'Hello {}'.format(name)
Exemple #3
0
class HelloReq(BaseView):
    """
        /hello-req -> 404
        /hello-req/foo -> 'Hello Foo'
    """
    # making the rule absolute disables the default rule that would have been created by the class.
    rule('/hello-req/<name>')

    def get(self, name):
        return 'Hello {}'.format(name)
Exemple #4
0
class HelloWorld(BaseView):
    """
        /hello -> 'Hello World'
        /hello/foo -> 'Hello Foo'
    """
    # relative URL indicates this route should be appended to the default rule for the class
    rule('<name>')

    def get(self, name='World'):
        return 'Hello {}'.format(name)
Exemple #5
0
class ExplicitRoute(BaseView):
    """
        /explicit-route -> 404
        /some-route/foo -> 'get some-route'
    """
    # absolute URL indicates the default class URL will not be generated
    rule('/some-route')

    def get(self):
        return 'get some-route'
Exemple #6
0
class Misc(BaseView):
    rule('/misc')
    rule('foo')
    rule('/misc2')
    rule('bar', post_only=True)

    def get(self):
        return 'get'

    def post(self):
        return 'post'

    @route('/an-abs-url')
    def an_abs_url(self):
        return 'found me'

    @route('8')
    @route('9')
    def two_routes(self):
        return '17'