Blog

Luis Majano

May 17, 2010

Spread the word


Share your thoughts

Thanks to our 3.0.0 milestones, the SES capabilities have been really fine tuned and added some great concepts in order to enable it for more RESTful applications.  We have added things like:

  • -alpha : Alpha only placeholders
  • {X} : Digit quantifiers for all placeholders
  • constraints : A separate structure where you can give any placeholder your own regular expression
  • RESTful actions : A way to split actions according to the incoming HTTP method

The last one is what we will concentrate on.  In true RESTful style URLs, we must concentrate on the concept of resources or endpoints we are trying to describe.  Say: http://www.example.com/users  most likely will represent users, but we could also have: http://www.example.com/users/lmajano which describes a user but with a more detailed part which is lmajano.

Requests and responses are built around the transfer of "representations" of "resources"

"Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use."

It is also important to note that REST is a style of URL architecture not a mandate, so it is an open avenue of sorts.  However, you must stay true to its concepts of resources and usage of the HTTP verbs.  Here are a few pointers when using the HTTP verbs:

  • POST : Create a resource
  • GET : Retrieve a resource(s)
  • PUT : Update a resource
  • DELETE : delete a resource

So examples for true RESTful URLs:

  • GET /users
    return a list of users
  • GET /users/lmajano
    return the representation of user lmajano
  • POST /users
    create a new user with post data
  • PUT /users/lmajano
    Update the lmajano user
  • DELETE /users/lmajano
    Delete the lmajano user

So how can we do this in ColdBox? Very easily! The new 3.0.0 SES interceptor allows for a pattern to be bounded to a handler and a structure of actions that match the incoming HTTP verbs:

// User representation addRoute(pattern="users/:user", handler="rest.Users", action={ GET = "show", POST = "create", DELETE = "remove", HEAD = "info" });

 

As you can see, the action argument can be a structure or a JSON structure of mappings between HTTP verbs and the action method you wish to fire whenever the resource is accessed with that method.  So if I go to /users/lmajano with a DELETE, then we will execute: rest.Users.remove().  So the approach of binding HTTP verbs to the correct actions, can give us TRUE RESTful URLs instead of us trying to create tons of URL representations and always using POST and GET. 

In conclusion, ColdBox 3.0.0 adheres to the standard RESTful principles and gives you a way to do HTTP verb to action mappings very easily when creating your resource URLs.  Stay tuned for more information on other useful RESTful features we have on 3.0 like:

  • HTTP method security right from within your handlers
  • onError() conventions when RESTful handlers throw exceptions
  • Request context updates to retrieve headers and content
  • Much more

Add Your Comment

Recent Entries

Ortus June 2024 Newsletter!

Ortus June 2024 Newsletter!

Welcome to the latest edition of the Ortus Newsletter! This month, we're excited to bring you highlights from our sessions at CFCamp and Open South Code, as well as a sneak peek into our upcoming events. Discover the latest developments in BoxLang, our dynamic new JVM language, and catch up on all the insightful presentations by our expert team. Let's dive in!

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang June 2024 Newsletter!

BoxLang June 2024 Newsletter!

We're thrilled to bring you the latest updates and exciting developments from the world of BoxLang. This month, we're diving into the newest beta release, introducing a new podcast series, showcasing innovative integrations, and sharing insights from recent events. Whether you're a seasoned developer or just getting started, there's something here for everyone to explore and enjoy.

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang 1.0.0 Beta 3 Launched

BoxLang 1.0.0 Beta 3 Launched

We are thrilled to announce the release of BoxLang 1.0.0-Beta 3! This latest beta version is packed with exciting new features and essential bug fixes, including robust encryption functionality, enhanced Java interoperability, and more efficient event handling. Key highlights include the introduction of query caching capabilities, seamless coercion of Java Single Abstract Method (SAM) interfaces from BoxLang functions, and support for virtual thread executors. So, let’s dive into the details of what’s new in BoxLang 1.0.0-Beta 3 and how you can start leveraging these updates today!

Luis Majano
Luis Majano
June 28, 2024