I have a question about how to create or build a simple API using laravel PHP framework. I have searched a lot in the net, but dont get a proper answer. Can anyone help me, Thanks in advance
Asked
Active
Viewed 353 times
0
-
1possible duplicate [http://stackoverflow.com/questions/18680396/how-to-build-a-rest-api-in-laravel-4-and-add-users](http://stackoverflow.com/questions/18680396/how-to-build-a-rest-api-in-laravel-4-and-add-users) – shyammakwana.me May 21 '14 at 05:44
-
Here is a [great tutorial](https://medium.com/laravel-4/c643022433ad), another tutorial from [tutsplus](http://code.tutsplus.com/tutorials/laravel-4-a-start-at-a-restful-api-updated--net-29785) – shyammakwana.me May 21 '14 at 05:51
-
@Technoknol - Is REST API and ordinary API are same? – Amesh May 21 '14 at 06:12
-
@Amesh - basically yes, they are the same. A REST API is just a way to build the API to confirm to some standards around urls etc. – Laurence May 21 '14 at 06:36
-
@Amesh Check out this http://stackoverflow.com/a/10596128/2219158 – shyammakwana.me May 21 '14 at 06:38
-
Check the dingo/api package for creating new API, if you don't want to build a lot of things from scratch. https://github.com/dingo/api – SUB0DH May 21 '14 at 06:47
1 Answers
0
One easy way is to just don't care about the views. For example:
In your UsersController.php
public function show($id) {
$users = User::all();
return $users;
}
Route.php
Route::get('/api/users', 'UsersController@show');
You'll then get a json object as response.
Then you can build it up with resources to get post, put etc to work. Read more in the laravel documentation: http://laravel.com/docs/routing
Laracasts has an entire series for building APIs: https://laracasts.com/series/incremental-api-development

Jimmie Johansson
- 1,875
- 1
- 19
- 39