Our product has three main sources where our REST api will be used.
All three calls our rest api’s which is a single codebase and share data.
What would be the ideal way to have the subdomains declared for these api types?
b2b.api.domain.com/v1
b2c.api.domain.com/v1
sdk.api.domain.com/v1
b2b.domain.com - for b2b users
b2c.domain.com - for b2c users
sdk.domain.com - for sdk integrators
domain.com - main landing page for the whole platform
We detect the type of the user based on subdomain name and validate his role when we get a rest api request.
Do you see any issue with the naming convention followed? If so, whats the good approach?
It seems like that approach would work. Out of curiosity, have you experimented with simply using the user to determine the type, rather than the subdomain? In other words, using a unified login and after logging in, you'd have access to what type of user it is and be able to show the correct landing based on that. Not sure if it'll fit your needs any better, but it could cut down on the number of subdomains needed.
What you said was true. The reason for adding subdomain for user type was just to make the signup and routing easier.
Each user has its own set of rest endpoints exposed. So to route them easily I was using the subdomains. Also, as you mentioned i check the user if he is a valid user based on his auth header.
Please let me know if the approach makes sense. I’m not an expert but learning self.
It appears like such strategy would be effective. Have you conducted any experiments where you just rely on the user to decide the type, rather than the subdomain, out of curiosity? Put simply, by utilizing a consolidated login process, once you successfully log in, you will be able to determine the user's identity and display the appropriate landing page accordingly.
Yes, that works but a B2B customer can be a B2C customer too in our use-case. So, if they want to use the same email login id, its allowed if it's custom domain per business.
The current approach of using subdirectories Garten Of Banban (e.g. /b2b, /b2c, /sdk) in the API endpoint URL is a valid option, drive mad but it does not use subdomains as you mentioned in your question.