2.11. 请求你的 API

未匹配的标注
本文档最新版为 2.0.0,旧版本可能放弃维护,推荐阅读最新版!

Making a request to your API is quite simple. The best way to do this is using a tool such as Postman.

Because we aren't versioning the API in the URI we need to define an Accept header to request a specific version. The header is formatted like so.

Accept: application/vnd.YOUR_SUBTYPE.v1+json

In the above example you would replace YOUR_SUBTYPE with the subtype name you defined in your configuration. Again, this is usually something unique to your application, such as its name or identifier, and is usually all lowercase.

Remember if you use a different standards tree, such as x, then you'd replace vnd with x.

Following the subtype name we have the version we want. In the above example we're requesting v1 of our API. This is then followed by a plus sign and the desired format. If the format is invalid the package will attempt to use the default format you defined in your configuration.

If you don't want to use Postman you can use a command line tool such as cURL.

$ curl -v -H "Accept: application/vnd.YOUR_SUBTYPE.v1+json" http://example.app/users

If you have strict mode enabled and you pass an invalid Accept header an unhandled Symfony\Component\HttpKernel\Exception\BadRequestHttpException will be thrown.

← OAuth 2.0 | API Blueprint Documentation →

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
发起讨论 查看所有版本


暂无话题~