Welcome Guest, Not a member yet? Register   Sign In
API version fallback
#1

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
api/v1/products
api/v1/invoices
...

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 Smile ... I'd like to design the app to accomplish this customization and at the same time be ready to respond to another different request from different tenants.  

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){

...
$routes->resource('invoices');
$routes->resource('products');
...

}); 
One possible way is to manually add all the new rules for the new endpoint api/v1b. 
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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB