Home

Previous Entry | Next Entry

Dispatch by request method

  • Nov. 13th, 2006 at 8:50 AM
me in B&W
I often find myself needing to make actions that should only be dispatched to by the POST method, or writing dispatch logic to distinguish between POST and GET in my various methods. It would be nice if the Catalyst dispatcher could handle this for me directly. However, we should probably support the whole HTTP spec, and adding those would pollute the attribute space pretty badly. Thus I suggest that we add a prefix, like do_POST or require_DELETE to the dispatch value. The other alternative is to add a method attribute, which would make the api look something like this

sub admin : Local Method('POST') {}

Obviously, it would have to match against specific methods first, then fall back on a generic handler without a specified method. Any other thoughts on the API?

Tags:

Comments

(Anonymous) wrote:
Nov. 13th, 2006 02:05 pm (UTC)
Form over Function
_METHODNAME is clunky. I'd much prefer the more official looking attribute: Method('POST')
(Anonymous) wrote:
Nov. 13th, 2006 06:02 pm (UTC)
I concur, Method(VERB) is the way to go, and should def support all the HTTP verbs.
(Anonymous) wrote:
Nov. 13th, 2006 06:29 pm (UTC)
Ack.
Method(FOO)++

Especially if it's implemented in the actions match, so it can be used together with chained, e.g.:

sub foo: Chained CaptureArgs(1) {
    setup_widget(); 
}

sub show: Chained('foo') PathPart('') Method(GET) {
    display_form();
}

sub proc: Chained('foo') PathPart('') Method(POST) {
    process_form();
}


gr.,
phaylon
[info]rjray wrote:
Nov. 14th, 2006 12:30 am (UTC)
Speaking from a vantage of only recently getting to work with Catalyst, I too would prefer the "Method('VERB')" approach. For one thing, it makes it easier to expand into new verbs if/when the HTTP spec adds them. Heck, you can use plug-ins at the Apache level to add your own verbs now.

I know from the existing Catalyst-based code that I've contributed to, at least 75% of their "Local" actions followed a predictable formula:

        IF method is "POST" THEN
            return immediately, let view render the template for this path
        ELSE
            process the form
            Use $c->response->redirect() to go to a different template
        ENDIF


Randy
[info]plasmasturm.org wrote:
Nov. 15th, 2006 12:08 am (UTC)

I’d say add very short shortcuts for the common verbs, eg. sub admin : Local POST {}, but support Method('FOO') for stuff beyond that. The list of common verbs would be (I think) just GET, PUT, POST, DELETE and HEAD.

Note: HTTP is case sensitive. Please don’t make POST/Method('POST') synonymous with Method('post').

Advertisement

Latest Month

June 2009
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
282930    

Page Summary

Powered by LiveJournal.com
Designed by Tiffany Chow