Kiran Rao
unread,Mar 24, 2012, 1:47:51 AM3/24/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to play-fr...@googlegroups.com
I am using Play! framework for developing a RESTful API. I am exploring ways of including a version number in the API URL - like so:
/myapi/v1.0/dogs
This would fetch a list of all dogs using API version 1.0
Obviously, if I increment to a new version, I might still want to serve the old version alongside.
/myapi/v2.0/dogs
How would one go about doing this? I can think of two primary paths:
Single Controller across Versions:
In this approach, the controller actions receive the API version as an argument, and then take the appropriate action based on this version number
GET /myapi/{version}/dogs DogsController.list
And then:
static void list(String version){
if("v1.0".equals(version)){
//Do the version 1.0 logic
} else { //if 2.0, then do the 2.0 logic
}
}
Have separate Controllers for each version:
The routes file might look like this:
GET /myapi/v1.0/dogs DogsControllerv1_0.list
GET /myapi/v2.0/dogs DogsControllerv2_2.list
Is there a way these 2 approaches can be combined? i.e., is there a way I can write a piece of Java code which examines the version string and dynamically invokes a particular Controller?