GET/POST/PUT/DELETE ??

I’d like to create a restful service without having to define any specific routes for each “verb”.

I know that I can specify routes for the specific methods, but I think I saw an example somewhere where these were defined in the handlers and not in the routes file… can anyone point me to such an example?

Thanks!

If you generate a handler you will see some code at the top that allows you to put verb restrictions on handler methods. Ie. this.allowedMethod = {delete=‘POST,DELETE’, index=‘GET’}

Nolan Dubeau

Load .,8,1

You can define a single route that understands which action to execute based on the “verb”.

addRoute(pattern="/api/user/:username",
handler=“rest.User”,
action={
GET = “show”,
DELETE = “remove”,
POST = “create”,
PUT = “update”

});

Aaron/Luis,

If I may ask a dumb question but why are routes defined in the routes.cfm? It seems it would make more sense to define them in the handlers. Just curious…


Jeremy R. DeYoung
Phone:615.261.8201

RantsFromAMadMan.com

Pretty much the decision to have them outside of your handler implementation is to have them decoupled from the handlers. Also, there is one routing table you can look at instead of tons of handler code. And also, you can create mutliple routes that point to the same handler methods instead of binding a handler method to only one route.

That’s pretty much why it is separate and not in the handler itself.

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Awesome. Just curious.

Loving 3.1 btw


Jeremy R. DeYoung
Phone:615.261.8201

RantsFromAMadMan.com

Luis must have stolen my email from the outbox :slight_smile: