0

I am kind of new to pylons and I have the task of designing a API versioning system. I want to store the different versions of the APIs in different folders. For example:

controllers/APIVersion/v1/clientAPI.py -- Version 1
controllers/APIVersion/v2/clientAPI.py -- Version 2
controllers/APIVersion/v3/clientAPI.py -- Version 3

The requests to get to these APIs should look like this:

curl 'http://mySite/v1/clientAPI/get/' -- Should bring me to the first version
curl 'http://mySite/v2/clientAPI/get/' -- Should bring me to the second version

I know I can do this through routing.py. This was my first idea that didn't seem to work:

map.connect('/APIVersion/{version}/{controller}/{action}')

Any ideas on how to route to the desired location? Also, feel free to comment on my versioning approach. I welcome the advice.

kmdent
  • 1,505
  • 15
  • 29

1 Answers1

0

The first thing Routes sees is the URL (which is also the first argument to connect). You're trying to access the API using URLs like /v1/clientAPI/get/ but you've configured your routing.py with routes like /APIVersion/{version}/{controller}/{action}. So there's no match.
The simplest "fix" would be use URLs like http://mySite/APIVersion/v1/clientAPI/get/ for v1 or http://mySite/APIVersion/v2/clientAPI/get/ for v2 and so on (you'll also need to make sure that APIVersion & all v1 to vX are packages + the controller class in each clientAPI.py is called ClientapiController).
If that's not an option (as in you still want to use URLs like /v1/clientAPI/get/ but have the controllers directory layout like /APIVersion/v1/clientAPI/get/) than you'll need to use a method similar to the one listed here.

Eugen Constantin Dinca
  • 8,632
  • 2
  • 28
  • 50