Download the PHP package hongxunpan/simple-api without Composer

On this page you can find all versions of the php package hongxunpan/simple-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package simple-api

simple-api

hongxunpan/simple-api 为 hongxunpan/simple-framework 提供可按需安装、显式启用的 JSON Response 与 JSON 异常渲染机制。

本包负责:

本包不提供任何默认异常映射,也不负责业务错误码、路由错误策略、鉴权、Token、RBAC、 SQL 调试、日志 Channel、第三方异常上报或 Eloquent 序列化。默认响应结构可由项目继承 扩展或完全替换;底层 JsonResponse 仍支持任何 json_encode 可编码的内容。

安装与启用

Composer 安装与 Module 启用是两个独立动作。API Module 首版没有 helper、项目配置文件、 发布资源或 Installer。

普通响应

启用后,普通路由返回值由 StandardJsonResponse 包装并编码:

StandardResponseContent 通过 ResponseContentContract 继承 Illuminate Arrayable, 负责把响应内容转换为通用数组;StandardJsonResponse 只负责使用该内容并发送 JSON。 项目如果不需要默认结构,可将 ResponseContract 直接绑定到纯 JsonResponse。

完整异常仍由 framework 的 ExceptionReporter 处理。simple-api 不绑定 Reporter, 也不读取日志配置。

异常策略边界

simple-api 不识别 RouteException、业务异常或第三方异常,也不决定 HTTP 200、404、405 或 500。Module 启用后 Registry 默认为空,项目应至少登记一个能够处理全部 Throwable 的兜底 Mapper,才能保证所有异常都返回项目约定的 JSON。

如果没有 Mapper 命中,JsonExceptionRenderer 会明确失败,framework ErrorHandler 随后回退到安全纯文本 Renderer。这个回退只保证不泄漏原始异常,不代替项目定义 JSON 错误协议。

项目响应覆盖

项目可以继承默认内容实现,增加稳定的项目字段:

项目 Response 负责选用该内容实现以及扩展 Header:

再由项目 Provider 将 framework 的 ResponseContract 绑定到 ProjectResponse。 项目 Provider 应登记在 config('module.provider-override'),其注册顺序晚于 Module Provider。 如果调用方已经返回任意 ResponseContentContract 实现,StandardJsonResponse 会直接使用, 不会再次包装。

项目异常映射

项目异常不需要继承 simple-api 的异常基类。项目实现 ExceptionMapper,自行决定异常分类、 HTTP 状态、响应结构和安全文案:

项目 Provider 登记 Mapper:

多个 Mapper 按顺序匹配,第一个非空结果生效。项目可将具体异常 Mapper 放在前面,并将 兜底 Mapper 放在最后。Mapper 或 JSON Renderer 自身失败时,framework ErrorHandler 会继续回退到安全纯文本 Renderer。

验证

测试覆盖 Module 元数据、Arrayable 内容契约、默认响应结构、纯 JSON 编码、Header 与状态 校验、项目内容扩展、Mapper 优先级与未命中行为、Provider 覆盖顺序以及项目最终 Response 绑定。


All versions of simple-api with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
ext-json Version *
hongxunpan/simple-framework Version ^0.3
illuminate/contracts Version ^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hongxunpan/simple-api contains the following files

Loading the files please wait ...