PHP code example of nicklaw5 / larapi
1. Go to this page and download the library: Download nicklaw5/larapi library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nicklaw5 / larapi example snippets
'providers' => array(
...
Larapi\LarapiServiceProvider::class,
);
Larapi::ok(); // 200 HTTP Response
Larapi::created(); // 201 HTTP Response
Larapi::accepted(); // 202 HTTP Response
Larapi::noContent(); // 204 HTTP Response
// app/Http/routes.php
Route::get('/', function()
{
return Larapi::ok();
});
// app/Http/routes.php
Route::get('/', function()
{
$data = [
['id' => 1, 'name' => 'John Doe', 'email' => '[email protected] '],
['id' => 2, 'name' => 'Jane Doe', 'email' => '[email protected] ']
];
return Larapi::ok($data);
});
// app/Http/routes.php
Route::get('/', function()
{
$data = [
['id' => 1, 'name' => 'John Doe', 'email' => '[email protected] '],
['id' => 2, 'name' => 'Jane Doe', 'email' => '[email protected] ']
];
$headers = [
'Header-1' => 'Header-1 Data',
'Header-2' => 'Header-2 Data'
];
return Larapi::ok($data, $headers);
});
Larapi::badRequest(); // 400 HTTP Response
Larapi::unauthorized(); // 401 HTTP Response
Larapi::forbidden(); // 403 HTTP Response
Larapi::notFound(); // 404 HTTP Response
Larapi::methodNotAllowed(); // 405 HTTP Response
Larapi::conflict(); // 409 HTTP Response
Larapi::unprocessableEntity(); // 422 HTTP Response
Larapi::internalError(); // 500 HTTP Response
Larapi::notImplemented(); // 501 HTTP Response
Larapi::notAvailable(); // 503 HTTP Response
// app/Http/routes.php
Route::get('/', function()
{
return Larapi::badRequest();
});
// app/Http/routes.php
Route::get('/', function()
{
$errorCode = 4001;
$errorMessage = 'Invalid email address.';
return Larapi::badRequest($errorMessage, $errorCode);
});
// app/Http/routes.php
Route::get('/', function()
{
$errorCode = 4001;
$errors = [
'email' => 'Invalid email address',
'password' => 'Not enough characters',
];
$headers = [
'Header-1' => 'Header-1 Data',
'Header-2' => 'Header-2 Data'
];
return Larapi::badRequest($errors, null, $headers);
});