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

I have built my web application on Codeigniter 3. Now, I want to build mobile apps on top of it.

What's the best way to structure Codeigniter to do this?

I am thinking of having an "api" folder within the controller folder.

Anyone has experience doing this?
Reply
#2

(01-04-2016, 11:43 AM)komirad Wrote: I have built my web application on Codeigniter 3. Now, I want to build mobile apps on top of it.

What's the best way to structure Codeigniter to do this?

I am thinking of having an "api" folder within the controller folder.

Anyone has experience doing this?

How are you building your mobile app?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

(01-04-2016, 02:05 PM)albertleao Wrote:
(01-04-2016, 11:43 AM)komirad Wrote: I have built my web application on Codeigniter 3. Now, I want to build mobile apps on top of it.

What's the best way to structure Codeigniter to do this?

I am thinking of having an "api" folder within the controller folder.

Anyone has experience doing this?

How are you building your mobile app?

I haven't actually started building it. So far, I have only done some research on the tools available (such as PhoneGap)
Reply
#4

Yes, have an API Controller and have it spit out JSON for the most part (nice and easy to parse in pretty much any mobile app)
Reply
#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




Theme © iAndrew 2016 - Forum software by © MyBB