To Make an API Centric Application or Not? - Laravel To Make an API Centric Application or Not? - Laravel codeigniter codeigniter

To Make an API Centric Application or Not? - Laravel


It is definitely worth it.

I am currently redesigning a messy PHP code for an established hosting company turning it into beautiful Laravel code. I already have a mobile app working with it - Laravel makes it easy to return JSON data with one line -

Response::json('OK', 200);

or

Response::eloquent(Auth::user());

or

$tasks = Task::all();Response::eloquent($tasks);

You don't need to use CURL as far as I know. You can make all requests with simple AJAX, jQuery would simplify that.

Also using some MVC JS framework would help you make the application code structure more elegant for the client side, and the advantage is that you can easily package that into PhoneGap when you are ready to have your API take some real testing.

Today I posted on my blog about a simple example that you can try to see if this approach is worth your time : http://maxoffsky.com/code-blog/login-to-laravel-web-application-from-phonegap-or-backbone/

Check it out and accept the answer if you think it's on the right track.


As always, your results may vary, but this is exactly what I'm going through at the moment. I'm migrating a large .Net site with this API architecture and I've decided to keep it for Laravel.

I personally decided for this because:

  1. More scalable. I can setup api.domain.com and then add additionalboxes/vm/whatever as our traffic grows. In fact, you could loadbalance just the api by "round robin" or multiple dns entries forthat domain.

  2. Future proofing for new sites and apps. Sounds like you're in thesame situation. I can see an app or two being added in the next yearor so.

  3. Lost cost. You'll already be laying out your controllers, so reallyit can be just a matter of setting them to RESTful and making smalltweaks to accommodate.

To be fair, some counter points:

  1. Possibly additional load time, from processing through the API, though this should be minimal.

  2. Additional security items to consider if you'd like to lock things down to just your app.

Either way, welcome to Laravel!


and what is the easiest way/s to make calls to the API without having to write a bazillion lines for cURL everytime I want to make a request?

@Sneaksta try postman chrome extension for calling rest services. you can create forms in this extension and pass data from these forms to you Rest serviceshttps://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?utm_source=chrome-ntp-icon