Skip to content

Commit 3f060db

Browse files
author
Lupacescu Eduard
authored
Docs (#88)
* Auth documentation * Auth documentation * Main readme * Field docs * Rest methods * Apply fixes from StyleCI (#84) * Exception handler * Apply fixes from StyleCI (#85) * Homepage * Search documentation * Apply fixes from StyleCI (#86) * Main * Align meta and links * Apply fixes from StyleCI (#87) * Format related for details into the according repository * Remove throw doc. * Apply fixes from StyleCI (#89) * Fix test
1 parent cb65bb4 commit 3f060db

File tree

20 files changed

+1177
-256
lines changed

20 files changed

+1177
-256
lines changed

config/config.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55

66
return [
77
'auth' => [
8-
//Table with authenticatable resource
8+
/*
9+
|--------------------------------------------------------------------------
10+
| Table containing authenticatable resource
11+
|--------------------------------------------------------------------------
12+
|
13+
| This configuration contain the name of the table used for the authentication.
14+
|
15+
*/
16+
917
'table' => 'users',
1018
],
1119

@@ -14,9 +22,8 @@
1422
| Restify Base Route
1523
|--------------------------------------------------------------------------
1624
|
17-
| These middleware will be assigned to every Restify route, giving you the
18-
| chance to add your own middleware to this stack or override any of
19-
| the existing middleware. Or, you can just stick with this stack.
25+
| This configuration is used as a prefix path where Restify will be accessible from.
26+
| Feel free to change this path to anything you like.
2027
|
2128
*/
2229

docs/.vuepress/config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ module.exports = {
2828
path: '/docs/repository-pattern/field',
2929
},
3030
{
31-
title: 'REST methods',
31+
title: 'Rest Controller',
3232
path: '/docs/rest-methods/rest-methods',
3333
},
3434
{
35-
title: 'Error handler',
36-
path: '/docs/exception-handler/exception-handler',
35+
title: 'Filtering',
36+
path: '/docs/search/search',
3737
},
3838
{
3939
title: 'Auth service',
4040
path: '/docs/auth/auth',
4141
},
42+
{
43+
title: 'Error handler',
44+
path: '/docs/exception-handler/exception-handler',
45+
},
4246
]
4347
},
4448
plugins: [

docs/README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
home: true
33
heroImage: /assets/img/logo.svg
44
heroText: Laravel Restify
5-
tagline: REST API + Auth
6-
actionText: Just do it
5+
tagline: A package to start a Rest API
6+
actionText: Docs
77
actionLink: /docs/
88
features:
9+
- title: Magic CRUD over entities
10+
details: Enjoy powerful "CRUD" over your entities in seconds
911
- title: Authentication with Passport
10-
details: Login, register, reset password, forgot password emails served for you
11-
- title: Powerful Response maker
12-
details: Enjoy the dev experience of Laravel API by using handy response helpers
13-
- title: Generic Exceptions
14-
details: Exceptions we usually use in every API project. Easy way of handling exception in your frontend application.
12+
details: Login, register, reset password, forgot password emails - served for you
13+
- title: Handy Response maker
14+
details: Enjoy the dev experience of Restify API by using consistent response helpers
15+
- title: Powerful Searching
16+
details: Built in filtering, sorting, matching and much more configurable features
17+
- title: Exception handler
18+
details: Make your API more suggestive by giving readable exceptions
19+
- title: JSON:API consistency
20+
details: Maintain your API consistent according with https://jsonapi.org
21+
1522
footer: MIT Lice

docs/docs/README.md

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,50 @@ Laravel Restify has a few requirements you should be aware of before installing:
1515
composer require binaryk/laravel-restify
1616
```
1717

18+
## Setup Laravel Restify
19+
After the instalation, the package requires a setup process, this will publish configuration, provider and will create the
20+
`app/Restify` directory with an abstract `Repository` and scaffolding a `User` repository you can play with:
21+
22+
```shell script
23+
php artisan restify:setup
24+
```
25+
1826
:::tip Package Stability
1927

20-
If you are not able to install Restify into your application because of your `minimum-stability` setting, consider setting your `minimum-stability` option to `dev` and your `prefer-stable` option to `true`. This will allow you to install Laravel restify while still preferring stable package releases for your application.
28+
If you are not able to install Restify into your application because of your `minimum-stability` setting,
29+
consider setting your `minimum-stability` option to `dev` and your `prefer-stable` option to `true`.
30+
This will allow you to install Laravel Restify while still preferring stable package
31+
releases for your application.
2132
:::
2233

23-
That's it!
24-
25-
Next, you may extend the `Binaryk\LaravelRestify\Controllers\RestController` and use its helpers:
26-
27-
```php
28-
class UserController extends RestController
29-
{
30-
/**
31-
* Display a listing of the resource.
32-
*
33-
* @return JsonResponse
34-
*/
35-
public function index()
36-
{
37-
$users = User::all();
38-
39-
return $this->respond($users);
40-
}
41-
}
34+
## Quick start
35+
36+
Having the package setup and users table migrated, you should be good to perform the first API request:
37+
38+
```http request
39+
GET: /restify-api/users?perPage=10
4240
```
4341

44-
## Authentication service
45-
46-
For each API we have to implement the auth module from scratch. With Laravel Restify this is not a pain anymore:
47-
48-
```php
49-
class AuthController extends Binaryk\LaravelRestify\Controllers\RestController
50-
{
51-
/**
52-
* @var Binaryk\LaravelRestify\Services\AuthService
53-
*/
54-
protected $authService;
55-
56-
public function __construct(Binaryk\LaravelRestify\Services\AuthService $authService)
57-
{
58-
$this->authService = $authService;
59-
}
60-
61-
/**
62-
* @param RestifyLoginRequest $request
63-
* @return Illuminate\Http\JsonResponse|string|void
64-
* @throws \Binaryk\LaravelRestify\Exceptions\CredentialsDoesntMatch
65-
* @throws \Binaryk\LaravelRestify\Exceptions\PassportUserException
66-
* @throws \Binaryk\LaravelRestify\Exceptions\UnverifiedUser
67-
*/
68-
public function login(RestifyLoginRequest $request)
69-
{
70-
$credentials = $request->only('email', 'password');
71-
$response = $this->response();
72-
73-
try {
74-
$token = $this->authService->login($credentials);
75-
76-
$response->data(['token' => $token])->message(__('Authentication with success'));
77-
} catch (CredentialsDoesntMatch | UnverifiedUser | PassportUserException $e) {
78-
$response->addError($e->getMessage())->auth();
79-
}
80-
81-
return $response->respond();
82-
}
83-
}
42+
This should return the users list paginated and formatted according to [JSON:API](https://jsonapi.org/format/) standard.
43+
44+
## Generate repository
45+
46+
Creating a new repository can be done via restify command:
47+
48+
```shell script
49+
php artisan restify:repository Post
50+
```
51+
52+
If you want to generate the Policy, Model and migration as well, then you can use the `--all` option:
53+
54+
```shell script
55+
php artisan restify:repository Post --all
8456
```
57+
## Generate policy
58+
59+
Since the authorization is done through the Laravel Policies, a good way of generating a complete policy for an entity
60+
is by using the restify command:
8561

62+
```shell script
63+
php artisan restify:policy Post
64+
```

0 commit comments

Comments
 (0)