Skip to content

Commit d488ef9

Browse files
author
Shashank Jain
committed
Chore: update README.md
1 parent f84898b commit d488ef9

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,53 @@ This package provides a powerful Rest API functionality for your Laravel project
44
**Note**: This package is under development and not recommended for use in production.
55

66
## Setup
7-
1) Add this package to yor composer.json
7+
1) Add this package to your composer.json
88
```
99
"require": {
10-
"froiden/laravel-rest-api": "dev-master"
10+
"froiden/laravel-rest-api": "dev-master"
1111
}
1212
```
1313

14-
2) Run, `composer update`.
14+
2) Run `composer update`
1515

16-
3) Add service provider and alias in `app.php`
16+
3) Add service provider and facade alias in `app.php`
1717

1818
```
1919
'providers' => [
20-
...
21-
\Froiden\RestAPI\Providers\ApiServiceProvider::class
22-
...
20+
...
21+
\Froiden\RestAPI\Providers\ApiServiceProvider::class
22+
...
2323
];
2424
2525
'alias' => [
26-
...
27-
"ApiRoute" => \Froiden\RestAPI\Facades\ApiRoute::class
28-
...
26+
...
27+
"ApiRoute" => \Froiden\RestAPI\Facades\ApiRoute::class
28+
...
2929
];
3030
```
3131

3232
## Usage
3333
1) Extend your eloquent model from `ApiModel` class instead of `Model` class
34+
3435
```
3536
class User extends ApiModel
3637
{
3738
...
3839
}
3940
```
41+
4042
2) Extend your controller from `ApiController` class and define the property $model to contain the class name of the User model
4143

4244
```
4345
class UserController extends ApiController
4446
{
45-
protected $mode = User::class;
47+
protected $model = User::class;
4648
}
4749
```
4850

4951
3) All the routes that will service the api should be defined though `ApiRoute` class. You can continue to use
5052
regular `Route` class for all other routes.
53+
5154
```
5255
ApiRoute::group(['middleware' => ['web', 'auth'], 'prefix' => 'api', 'namespace' => 'App\Http\Controllers'], function () {
5356
ApiRoute::resource('user', 'UserController');
@@ -61,18 +64,21 @@ Thats it! Your api endpoint `/api/user` will now work. All the REST methods - `i
6164
This package follows [Microsoft RestAPI Guidelines](https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md) - except the fields definition - which is inspired from Facebook Graph API.
6265

6366
### Parameters
64-
You can modify the results you get from `index` and `show` methods using various paramters as follows:
67+
68+
You can modify the results you get from `index` and `show` methods using various parameters as follows:
6569

6670
* **fields**: A comma separated list of fields you want to get in results, in following format:
71+
6772
```
68-
fields=id,name,comments.limit(10).order(chronological){id,text}
73+
fields=id,name,comments.limit(10).order(chronological){id,text}
6974
```
75+
7076
Here, `id` and `name` are normal database columns, and comments is a **relation**. If no fields are specified, results contain list of fields in` $defaults` array. By default, this array only has `id` field. You can override it in your model with your own default fields list.
7177

7278
* **filters**: A filter query with defined in [Microsoft RestAPI Guidelines - Filters](https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md#97-filtering). **Note:** for security reasons, filtering on all columns is disabled. You need to specify a list of columns in $filterable property in your model to allow the columns on which you want to allow filtering.
7379

7480
```
75-
filters=status eq "active" or (status eq "suspended" and deleted_at eq null)
81+
filters=status eq "active" or (status eq "suspended" and deleted_at eq null)
7682
```
7783
Apart from operators in the guidelines, one more operator - `lk` - is supported which corresponds to like query in MySQL.
7884

@@ -89,9 +95,10 @@ Saving and updating works out of the box, including relations. But, the fields r
8995
### Form request
9096

9197
If you use form requests for validation, simple store the request class's reference in the form request parameters in your controller:
98+
9299
```
93-
$indexRequest = UserIndexRequest::class;
94-
$storeRequest = UserStoreRequest::class;
100+
$indexRequest = UserIndexRequest::class;
101+
$storeRequest = UserStoreRequest::class;
95102
```
96103

97104
### Modifying query
@@ -107,8 +114,9 @@ public function modifyIndex($query) {
107114
### Relations endpoint
108115

109116
You can call relations endpoint to get only the relations. For example, to get a particular user's comments, you can call:
117+
110118
```
111-
GET /api/user/123/comments
119+
GET /api/user/123/comments
112120
```
113121

114122
## Contribution

0 commit comments

Comments
 (0)