Codeigniter, REST, versioning |
[eluser]Unknown[/eluser]
Hi all, im trying to use CI for a RESTful api but im having a bit of a problem seeing the 'right' CI and 'right' REST way to do things. Im using 2.0.3 and the excellent REST_Controller by Phil. In the religiously correct way to implement versions in a REST api, I would pass the version in a http header. For instance. GET /api/users Accept: application/json; version=1.1 Let's say I have 3 versions of my API. 1.0, 1.1 and 2.0. Getting the API Version from the header is not difficult. So, in CI i would land in application/controllers/api.php, and method users_get() (the _get is a REST_Controller addition) So now my problem is, how to implement versions in a somewhat manageable way. Id prefer versions to exist in standalone entities. Is there a CI-way to do this? Would it be possible to detect the version before the controller is called, and decide before loading the controller php file (api.php) to load a different php file, lets say api_1.1.php? Or is there another way to achieve something similar? Now to add another layer of difficulty to this problem. I need to support multiple APIs from the same system. So, for instance: https://api.XYZ.com/otp/users https://api.XYZ.com/mail/domains Where the otp and mail are totally different APIs to a different data store. I would prefer this all to be in separate directories: application/controllers/otp/.... application/controllers/mail/.... Would I use routing for this? And call say an otp.php and mail.php through routing? And can these 2 issues (versioning and routing) co-exist? Any pointers are greatly appreciated, Regards, Cor |
Welcome Guest, Not a member yet? Register Sign In |