Download the PHP package robinmarechal/laravel-rest-api without Composer

On this page you can find all versions of the php package robinmarechal/laravel-rest-api. 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-rest-api

Laravel Rest API

An easy to add a RESTful API to your Laravel's project

Usage example

The REST API is easy to use since it respects Laravel's name conventions and RESTful API's standards.

For example, imagine you have a posts table in your database, then you'll want to get all the posts from your API, running on the server myserver.com. To do that, you'll simply have to request the following URL:

If you only want the post with id 4:

If you want the comments of the 4th post:

Remark: In this case, you need to specify that the posts table (the Post model) has a relation named comments. We will speak about that later.

Finally, if you want the 3rd comment of the 4th post:

Of course, it's also possible to add (POST), update (PUT/PATCH) and delete (DELETE) data. See the documentation.

Installation

Download the package:

Laravel >= 5.5

The package is using Laravel's auto discovery feature. The Service Provider is therefore automagically loaded.

Laravel <= 5.4

Add the RestApiServiceProvider to your app's provider list in the file config/app.php:

Final Step

Make your parent controller class (by default it's app/Http/Controllers/Controller.php) use the RobinMarechal\RestApi\HandleRestRequest trait.

If you want to create custom routes with custom handlings, you may want to access the request in your child controllers. Therefore, you should add a constructor to the Controller parent class like this:

Prepare your(self) API

Once you've installed the package, you just need to create the required structure. For each of your database's tables (except the pivots), you need to create a Controller and a Model.

The API controllers are located in app/Http/Controllers/Rest/, and the models are in app/.

The controller's names should be you your table's names, in camel case and in plural form. The model's names should be your table's name, in camel case and in singular form.

For example, if you have a posts table, you should have a controller named PostsController in app/Http/Controllers/Rest/, and a model named Post in app/.

Of course, all of these are customizable, you only need to publish the rest config using php artisan vendor:publish command to override defaults

But there's a command for this!

I've created an Artisan's command that helps us to create these controllers and models. To create the controller and the model for a database table, simply execute the following command:

_Note: If you don't specify the function name option (<function_name>), the name will be your related model (<related_model>) in snake case, in plural form for hasMany and belongsToMany methods, and in singular form for hasOne and belongsTo methods._

Example:

Important: Don't forget the quotes for the --relations options!

This example will create the following files:

Controller:

app/Http/Controllers/Rest/PostsController.php

Model:

app/Post.php

Once you've done the same for users and comments table, you're ready to use your REST API. For example, you can call these URLs:

But that's not the end!

The strenght of this package is that it allows you to write more complex API calls to retrieve specific data, even with a POST, PUT/PATCH and DELETE request. See the documentation.


All versions of laravel-rest-api with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ~5.6
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 robinmarechal/laravel-rest-api contains the following files

Loading the files please wait ....