API Blueprint is simple and accessible to everybody involved in the API lifecycle. Its syntax is concise yet expressive. With API Blueprint you can quickly design and prototype APIs to be created or document and test already deployed mission-critical APIs
通俗一點就是一種接口規範,並且是使用markdown的,使用markdown的語法書寫接口。php
目前和前端聯調、其餘部門聯調使用的方式有:html
birjemin/blueprint
+aglio
/macdown
...組合,好比在接口的方法上面按照必定的格式進行註釋,而後使用該composer包生成apib文件,這個文件是一個遵循blueprint接口規範的markdown文件。可使用aglio插件搭建一個web服務(這個插件支持實時更新,不須要刷新頁面),也可使用macdown編輯器查看這個文件。1.安裝aglio(npm是啥???本身問前端同窗吧。。)前端
npm install -g aglio
請檢查是否安裝成功。node
2.給laravel項目引入composer包(包已經提交,不過國內鏡像還沒同步)laravel
composer require birjemin/blueprint dev-master
orgit
composer require birjemin/blueprint
3.在app.php
中添加BlueprintServiceProvider::class
程序員
4.給接口添加註釋,添加在Controller入口方法前面(詳細的註釋方式請查看https://github.com/dingo/api/wiki/API-Blueprint-Documentation)。github
/** * Class CarsController * @package App\Http\Controllers * @Resource("CarResource", uri="/api/cars") */ class CarController extends Controller { /** * cars list * * Get current cars list * * @Get("/list") * @Transaction({ * @Request(identifier="page=1&type=1"), * @Response(200, body={"msg": "返回成功","code": 200,"page": 1,"timestamp": "1522673813","data":{"result":[{"price": "2200","type": "福特","notice": "豪車"},{"price": "2200","type": "大衆","notice": "車"}]}}) * }) * @Parameters({ * @Parameter("page", type="integer", required=true, description="分頁", default=1), * @Parameter("search", type="string", required=false, description="搜索條件"), * @Parameter("type", type="integer", required=true, description="汽車類型", default=1, members={ * @Member(value="1", description="新車"), * @Member(value="2", description="舊車") * }) * }) */ public function index() { return json_decode('{"succ":true,"code":0,"message":"","data":{"result":true}})'); } }
@Response(200, body={...}
中的[
和]
要替換成{
和}
,這裏不替換是由於個人博客使用了jekyll
,github報錯啦~~
5.建立apib
文件web
php artisan birjemin:docs --output-file=tianming.apib
項目下面生成了tianming.apib文件,這個是一個markdown文件,能夠直接用markdown編輯器打開,下面講一下aglio的web服務。express
6.運行aglio服務(詳細的命令能夠去https://github.com/danielgtaylor/aglio查看)
aglio -i tianming.apib -s
7.訪問:http://27.0.0.1:3000
(端口能夠自定義,這個是默認的)
1.返回的數據不能夠json若是是數組,{}
代替[]
這個符號,好比示例中的。
{"msg": "返回成功","code": 200,"page": 1,"timestamp": "1522673813","data":{"result":[{"price": "2200","type": "福特","notice": "豪車"},{"price": "2200","type": "大衆","notice": "車"}]}}
就要將裏面的中括號替換成大括號!
2.這些註釋寫錯了會報錯哦~
3.和apidoc的註釋有區別~~