francescomalatesta/laravel-api-boilerplate-jwt
Composer 安装命令:
composer create-project francescomalatesta/laravel-api-boilerplate-jwt
包简介
An API Boilerplate to create a ready-to-use REST API in seconds.
README 文档
README
Laravel API Boilerplate is a "starter kit" you can use to build your first API in seconds. As you can easily imagine, it is built on top of the awesome Laravel Framework. This version is built on Laravel 5.8!
It is built on top of three big guys:
- JWT-Auth - tymondesigns/jwt-auth
- Dingo API - dingo/api
- Laravel-CORS barryvdh/laravel-cors
What I made is really simple: an integration of these three packages and a setup of some authentication and credentials recovery methods.
Installation
- run
composer create-project francescomalatesta/laravel-api-boilerplate-jwt myNextProject; - have a coffee, nothing to do here;
Once the project creation procedure will be completed, run the php artisan migrate command to install the required tables.
Usage
I wrote a couple of articles on this project that explain how to write an entire sample application with this boilerplate. They cover the older version of this boilerplate, but all the concepts are the same. You can find them on Sitepoint:
Just be aware that some options in the config/boilerplate.php file are changed, so take a look to it.
WARNING: the articles are old and Laravel 5.1 related. Just use them as "inspiration". Even without updated tutorials, they should be enough.
Main Features
Ready-To-Use Authentication Controllers
You don't have to worry about authentication and password recovery anymore. I created four controllers you can find in the App\Api\V1\Controllers for those operations.
For each controller there's an already setup route in routes/api.php file:
POST api/auth/login, to do the login and get your access token;POST api/auth/refresh, to refresh an existent access token by getting a new one;POST api/auth/signup, to create a new user into your application;POST api/auth/recovery, to recover your credentials;POST api/auth/reset, to reset your password after the recovery;POST api/auth/logout, to log out the user by invalidating the passed token;GET api/auth/me, to get current user data;
Separate File for Routes
All the API routes can be found in the routes/api.php file. This also follow the Laravel 5.5 convention.
Secrets Generation
Every time you create a new project starting from this repository, the php artisan jwt:generate command will be executed.
Configuration
You can find all the boilerplate specific settings in the config/boilerplate.php config file.
<?php return [ // these options are related to the sign-up procedure 'sign_up' => [ // this option must be set to true if you want to release a token // when your user successfully terminates the sign-in procedure 'release_token' => env('SIGN_UP_RELEASE_TOKEN', false), // here you can specify some validation rules for your sign-in request 'validation_rules' => [ 'name' => 'required', 'email' => 'required|email', 'password' => 'required' ] ], // these options are related to the login procedure 'login' => [ // here you can specify some validation rules for your login request 'validation_rules' => [ 'email' => 'required|email', 'password' => 'required' ] ], // these options are related to the password recovery procedure 'forgot_password' => [ // here you can specify some validation rules for your password recovery procedure 'validation_rules' => [ 'email' => 'required|email' ] ], // these options are related to the password recovery procedure 'reset_password' => [ // this option must be set to true if you want to release a token // when your user successfully terminates the password reset procedure 'release_token' => env('PASSWORD_RESET_RELEASE_TOKEN', false), // here you can specify some validation rules for your password recovery procedure 'validation_rules' => [ 'token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed' ] ] ];
As I already said before, this boilerplate is based on dingo/api and tymondesigns/jwt-auth packages. So, you can find many informations about configuration here and here.
However, there are some extra options that I placed in a config/boilerplate.php file:
sign_up.release_token: set it totrueif you want your app release the token right after the sign up process;reset_password.release_token: set it totrueif you want your app release the token right after the password reset process;
There are also the validation rules for every action (login, sign up, recovery and reset). Feel free to customize it for your needs.
Creating Endpoints
You can create endpoints in the same way you could to with using the single dingo/api package. You can read its documentation for details. After all, that's just a boilerplate! :)
However, I added some example routes to the routes/api.php file to give you immediately an idea.
Cross Origin Resource Sharing
If you want to enable CORS for a specific route or routes group, you just have to use the cors middleware on them.
Thanks to the barryvdh/laravel-cors package, you can handle CORS easily. Just check the docs at this page for more info.
Tests
If you want to contribute to this project, feel free to do it and open a PR. However, make sure you have tests for what you implement.
In order to run tests:
- be sure to have the PDO sqlite extension installed in your environment;
- run
php vendor/bin/phpunit;
Feedback
I currently made this project for personal purposes. I decided to share it here to help anyone with the same needs. If you have any feedback to improve it, feel free to make a suggestion, or open a PR!
francescomalatesta/laravel-api-boilerplate-jwt 适用场景与选型建议
francescomalatesta/laravel-api-boilerplate-jwt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.46k 次下载、GitHub Stars 达 1.17k, 最近一次更新时间为 2016 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「api」 「boilerplate」 「auth」 「laravel」 「jwt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 francescomalatesta/laravel-api-boilerplate-jwt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 francescomalatesta/laravel-api-boilerplate-jwt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 francescomalatesta/laravel-api-boilerplate-jwt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP class to extend when building a WordPress plugin allowing you to follow smart plugin setup standards.
Anax htmlform module.
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Laravel 5.7 Boilerplate based on Bootstrap 4 and Tabler for Backend.
WordPress Plugin Framework
统计信息
- 总下载量: 7.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1174
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-25