PHPackages                             robinmarechal/laravel-rest-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. robinmarechal/laravel-rest-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

robinmarechal/laravel-rest-api
==============================

An easy way to add a REST API to your project

v0.2.10(8y ago)0631PHP

Since May 2Pushed 7y ago1 watchersCompare

[ Source](https://github.com/RobinMarechal/laravel-rest-api)[ Packagist](https://packagist.org/packages/robinmarechal/laravel-rest-api)[ RSS](/packages/robinmarechal-laravel-rest-api/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (34)Used By (0)

Laravel Rest API
================

[](#laravel-rest-api)

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

Usage example
-------------

[](#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:

```
http://myserver.com/api/posts
```

If you only want the post with id 4:

```
http://myserver.com/api/posts/4
```

If you want the comments of the 4th post:

```
http://myserver.com/api/posts/4/comments
```

*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:

```
http://myserver.com/api/posts/4/comments/3
```

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

Installation
------------

[](#installation)

Download the package:

```
composer require robinmarechal/laravel-rest-api
```

#### Laravel &gt;= 5.5

[](#laravel--55)

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

#### Laravel &lt;= 5.4

[](#laravel--54)

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

```
'providers' => [
    //...
    RobinMarechal\RestApi\RestApiServiceProvider::class,
]
```

#### Final Step

[](#final-step)

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

```
