Welcome Guest, Not a member yet? Register   Sign In
Writing an API (for mobile app) on top of a web application?
#5

Generally, I just prefer to have my web application be as mobile-friendly as possible, rather than building specific apps for mobile platforms. However, when I absolutely need an API for an external application, I find it best to sit down and design the API with an eye towards the existing web application's structure. In some cases, a specific API end-point makes sense; in other cases, the API will largely be made up of additions to or extensions of my existing URL structure.

In either case, the ease of building a separate controller specifically for this purpose will depend on how easily I can use my existing resources from that controller. If all of my existing controllers are relatively thin and all of my business logic is built into my models or libraries, then it's relatively straight-forward to add a new controller which loads the existing libraries and models to build an API to work with the data.

On the other hand, if you need to work within the existing controllers, you may find it easier to use those controllers within your API. You might add new methods to existing controllers for the API end-points, and possibly refactor existing methods to extract the business logic (which you may want to move to libraries or models at some point).

No matter which method you use for the code structure, you can still use your routes config to define the external API, pointing specific API end-points at different controllers, or making routes which might normally point to different controllers route instead to your API controller.
Reply


Messages In This Thread
RE: Writing an API (for mobile app) on top of a web application? - by mwhitney - 01-08-2016, 11:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB