Download the PHP package malhal/laravel-restapi without Composer

On this page you can find all versions of the php package malhal/laravel-restapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-restapi

Laravel-RestApi

A controller and handler that lets you easily build a REST API in Laravel that uses fine grained CRUD resources. It also provides consistent error responses using Laravel's built-in exception handling.

First in your model you want to use be sure to add a $fillable param with all the fields you would like to populate via the API methods, e.g.

protected $fillable = ['name', 'formattedAddress', 'latitude', 'longitude'];

Note this is important because it is also used to hide these fields from output when not needed. E.g. when a record is created we do not want to send the data back down to client. It would be much more complicated to reflect these fields from the database so we simply make use of this property.

Then, make a controller subclass of RestController, e.g. VenueController:

use Malhal\RestApi\RestController;

class VenueController extends RestController
{

}

Finally, in your api.php routes file add:

Route::resource('venue', 'VenueController',  ['except' => [
    'create', 'edit'
]]);

Now you can POST to api/venue to create a venue, PUT to replace it, or PATCH to update it. You can also use GET to query or api/venue/1 to get an individial record.

As an added bonus, to support batch updates add:

$this->post('batch', '\Malhal\RestApi\RestController@batch');

And post a JSON with a requests array like this:

{
    "atomic" : true,
    "requests":
    [
        {
            "url" : "api/venue/1000",
            "method" : "PUT",
            "body" : {
                "name" : "Test Venue"
                }
        },
        {
            "url" : "api/password",
            "method" : "POST",
            "body" : {
                "password" : "12345679",
                "venue_id" : 1000
                }
        }
    ]
}

And set the atomic flag to make it rollback if a request fails.

If you want to add validation then simply override a method and change the query if necessary, e.g.

class PasswordController extends RestController
{
    public function index(Request $request)
    {
        $this->validateQuery($request, [
            'venue_id' => 'required|integer'
        ]);
        return $this->newModel()->where('venue_id', $request->get('venue_id'))->get();
    }

    public function store(Request $request){
        $this->validateJson($request, [
            'venue_id' => 'required|integer'
        ]);
        return parent::store($request);
    }
}

Now if a password is posted and is missing a venue_id then the following error is returned by the RestHandler:

{
  "error": "QueryException",
  "driverCode": "1364",
  "reason": "Field 'name' doesn't have a default value",
  "code": "HY000"
}

Installation

PHP 5.6.4+ and Laravel 5.3+ are required.

To get the latest version of Laravel-RestApi, simply require the project using Composer:


All versions of laravel-restapi with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.4
laravel/framework Version 5.3.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package malhal/laravel-restapi contains the following files

Loading the files please wait ....