Symfony 上的 API framework。但如果不是用 Symfony 呢?這時候就可以考慮用 neomerx/json-api 這套按 標準 (http://jsonapi.org/) 實作的 PHP library。
這 library 包含了其獨立的 encoder、schema(重造輪子?),它 Github 上的 wiki 有較詳細的 document。

A good API is one of most effective ways to improve the experience for your clients. Standardized approaches for data formats and communication protocols increase productivity and make integration between applications smooth.

This framework agnostic package implements JSON API specification version v1.0 and helps focusing on core application functionality rather than on protocol implementation. It supports document structure, errors, data fetching as described in JSON API Format and covers parsing and checking HTTP request parameters and headers. For instance it helps to correctly respond with Unsupported Media Type (HTTP code 415) and Not Acceptable (HTTP code 406) to invalid requests. You don’t need to manually validate all input parameters on every request. You can configure what parameters are supported by your services and this package will check incoming requests automatically. It greatly simplifies API development and fully support specification. In particular

    • – Resource attributes and relationships

 

    • – Polymorphic resource data and relationships

 

    • – Compound documents with inclusion of related resources (circular resource references supported)

 

    • – Meta information for document, resources, errors, relationship and link objects

 

    • – Parsing HTTP Accept and Content-Type headers in accordance with RFC 7231

 

    • – Parsing parameters for pagination, sorting and filtering

 

    • – Sparse fieldsets and customized included paths

 

    – Errors

Clients built around JSON API are able to take advantage of its features around efficiently caching responses, sometimes eliminating network requests entirely.

https://github.com/neomerx/json-api

發表回覆

你的電郵地址並不會被公開。 必要欄位標記為 *