I am developing a mobile application for existing web application, I need to have a separate router for mobile and web so I can do any changes in the future if I want.
How do I differentiate Mobile and Web Endpoints?
Something like this?
web - api.example.com/users/12
mobile- api.example.com/mobile/users/12
or using versions?
web - api.example.com/v1/users/12mobile- api.example.com/v2/users/12
Given that they should in most cases being REST accessing the same general data, why do they need different methods of passing said information?
Unless you're doing something silly and slow -- like passing markup mixed with the data and then slopping it in with innerHTML or similar outdated outmoded methodology -- there should be no reason to even be making that distinction for your REST access.
It is better to keep both end points the same, unless there is a real payload or performance overhead, For REST the path ideally should be locating the resource, hence using channels may not be a good idea. Typically platforms use versions to support backward compatibility. Open apis could be consumed from any channel, and web end points could be accessed from mobile devices via ajax.
Marco Alka
Software Engineer, Technical Consultant & Mentor
In the end, it doesn't really matter. You could also use a different subdomain...
web - api.example.com/users/12mobile- mobile-api.example.com/users/12they all do work and they probably all are adequate. This is something you have to decide on. What you have to do, though, is document what you decide on and why you have to use separate ones.