Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2458 (closed enhancement: fixed)

Opened 9 years ago

Last modified 9 years ago

[PATCH] Allow custom REST-like methods in RestController

Reported by: lento Owned by:
Priority: normal Milestone: 2.1b2
Component: TurboGears Version: 2.1
Severity: normal Keywords:
Cc:

Description

This allows to have a consistent API in case you have custom methods in your RestController, exposing them the same way as the default REST verbs.

For example you can define get_archive() and post_archive() in your "movies" controller from the moviedemo example:

    custom_actions = ['archive']

    @expose('moviedemo.templates.forms.form')
    def get_archive(self, movie_id, **kwargs):
        """Display a ARCHIVE confirmation form."""

    @expose('moviedemo.templates.forms.result')
    def post_archive(self, movie_id):
        """Archive a movie"""

or just

    custom_actions = ['archive']

    @expose('moviedemo.templates.forms.result')
    def archive(self, movie_id):
        """Archive a project"""

and use them like this:

GET /movies/1/archive

POST /movies/1?_method=ARCHIVE

Attachments

REST_custom_get_actions.patch Download (3.5 KB) - added by lento 9 years ago.

Change History

Changed 9 years ago by lento

comment:1 Changed 9 years ago by lento

  • Version changed from 2.0b7 to trunk

comment:2 Changed 9 years ago by jorge.vargas

  • Version changed from trunk to 2.1
  • Milestone changed from __unclassified__ to 2.1b2

This patch looks good.

comment:3 Changed 9 years ago by percious

  • Status changed from new to closed
  • Resolution set to fixed

implemented in  http://bitbucket.org/turbogears/tg-dev/changeset/39da27c2c339/ (2.1b2 release) uses _custom_actions instead of custom_actions for the attribute. Needs to be documented. Tests have been added for the use case.

Note: See TracTickets for help on using tickets.