| Package Data | |
|---|---|
| Maintainer Username: | devfactory |
| Maintainer Contact: | alcindo.dacosta@devfactory.ch (Alcindo Da Costa) |
| Package Create Date: | 2014-12-08 |
| Package Last Update: | 2016-03-09 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-30 03:10:40 |
| Package Statistics | |
|---|---|
| Total Downloads: | 604 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 1 |
| Total Watchers: | 4 |
| Total Forks: | 0 |
| Total Open Issues: | 1 |
Helpers to create an API for laravel 4.2
This module handle json and xml as response
##How to setup
update composer.json file:
{
"require": {
"devfactory/api": "1.0.*"
}
}
and run composer update from terminal to download files.
update app.php file in app/config directory:
'providers' => array(
'Devfactory\Api\ApiServiceProvider',
),
alias => array(
'API' => 'Devfactory\Api\Facades\ApiFacade',
),
##Configuration
php artisan config:publish devfactory/api
##How to use api in your route
the param {format} are not mandatory
Route::group(array('prefix' => 'v1'), function()
{
Route::get('foo.{format}', 'ApiV1\FooController@foo');
Route::post('bar.{format}', 'ApiV1\FooController@bar');
});
Route::group(array('prefix' => '{format}/v1'), function()
{
Route::get('foo', 'ApiV1\FooController@foo');
Route::post('bar', 'ApiV1\FooController@bar');
});
In you controller you can use
return Response::api(array("foo" => "bar"), 404);
return Response::api(array("ok"));
or
return API::createResponse(array("foo" => "bar"), 404);
return API::createResponse(array("ok"));
##To call your service you can use the Facade
API::get('v1/foo.json', array('foo' => 'bar'));
API::post('v1/bar.xml', array('foo' => 'bar'));
API::put('v1/bar.xml', array('foo' => 'bar'));