views:

196

answers:

1

Hi,

I'm finishing the API of our web service. Now I'm thinking on how to make the route changes, so if we decide to make a new version we don't break the first API.

right now:

url: /api/:action
param: { module: api, action: :action }
requirements:
  sf_format: (?:xml|json)

what i've thought:

url: /api/v1/:module/:action
param: { module: api1, action: :action }
requirements:
  sf_format: (?:xml|json)

url: /api/v2/:module/:action
param: { module: api2, action: :action }
requirements:
  sf_format: (?:xml|json)

That's easy, but the perfect solution would be to have the following kind of route

# Automatically redirects to one module or another
url: /api/v:version/:module/:action
param: { module: api:version, action: :action }
requirements:
  sf_format: (?:xml|json)

any ideas on how to do it? what do you recommend us to do?

thanks!

A: 

How about just use the old routing rules and append .xml1/.xml2/.json1/.json2 to the end? That way you can reuse your current modules and only need to create a new view ("indexSuccess.xml1.php").

Or create a new routing class?

Coronatus
that's a very good idea, but that only works if the controller action does the same thing in both cases. If they are slightly different I would need if/else to check versions to search for another param, or returning a different array, etc.
fesja