![]() |
API version fallback - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: API version fallback (/showthread.php?tid=82571) |
API version fallback - Jag81 - 07-25-2022 Hello everyone. I'm thinking about how to do this: API version fallback. I'd like to share my thoughts (and pseudo-code) to try to get how to do this in a good way (maybe some of you already made it). I have a complete application (multi-tenant app) that works with its own API. Endpoints are like: Code: api/v1/users Now, I have a particular user that needs to use the endpoint "products" in a different way. Let's say I want to please him ![]() Let's call them "premium users": they can ask for customizations from the regular default app. My first idea is this: All database users (tenants) need to have a "version" field (default 1). This way, I can manually set a different version to the premium user, for example, version 1b (or something that helps me better understand the customization I made for this user - I will figure out the naming later). This is my first challenge: I need to have routes based on the version field. My current route file reports what the doc explains, this is an example: PHP Code: $routes->group('api/v1', ['filter' => 'authFilter', 'namespace' => 'App\Controllers\Api\V1'], function($routes){ This may cause us to have a long route file in the future. Then, I could copy and paste the entire default version to the subfolder v1b/ but this does not sound good to me. I prefer to have only the custom endpoint file inside the new subfolder v1b/ and use the default one instead. I don't know how to do it yet ... in human lang, it sounds like this: If the api/{tenant_version}/endpoint exists then use it. Else, use the api/v1/endpoint Any idea or comments about all of this stuff? Thanks in advance. |