netlogix/webapi
Composer 安装命令:
composer require netlogix/webapi
包简介
Create jsonapi.org web apis in flow
README 文档
README
Installation
composer require netlogix/webapi
Accept-header driven exception handling
The package ships a PSR-15 middleware that catches exceptions inside the
middleware chain and turns them into a ResponseInterface. This way, any
response-decorating middleware (most importantly
Sitegeist.OffCORS:CorsMiddleware) sees a real response on errors and can
add its headers — which the default Flow exception path, running through
set_exception_handler, would bypass.
Components
Netlogix\WebApi\Http\Middleware\ExceptionToResponseMiddlewareCatches anyThrowablethrown by downstream middlewares and delegates rendering to the dispatcher below. Registered viaConfiguration/Settings.Middleware.yamldirectly afterSitegeist.OffCORS:CorsMiddleware.Netlogix\WebApi\Error\AcceptHeaderDependingExceptionHandlerPicks one of the configured FlowExceptionHandlerInterfaceimplementations based on the request'sAcceptheader (proper content negotiation viaNeos\Flow\Http\Helper\MediaTypeHelper), invokes it, and adapts itsheader()/echostyle output into a PSR-7 response.Netlogix\WebApi\Error\JsonExceptionHandlerRenders the throwable as a jsonapi.org-style error document ({"errors": [{…}]}) mirroring the shape produced byNetlogix\JsonApiOrg\Controller\ApiController::errorAction(). For plain throwables the entry carriescodeandtitle, plus an optionalidfromWithReferenceCodeInterface. Production-safe variant — does not publish the exception message.Netlogix\WebApi\Error\JsonDebugExceptionHandlerSame envelope asJsonExceptionHandler, but for plain throwables the error entry additionally carriesdetail(the exception message) and ametablock withexceptionType,file,line, a sanitizedtrace(frame args stripped) and a recursivemeta.previouschain — analogous to howNeos\Flow\Error\DebugExceptionHandlerextends theProductionExceptionHandler. Reserved for non-production contexts.
Exceptions implementing JsonSerializable provide the body of one
error entry (the jsonapi.org fields, e.g. code / title /
detail / meta). Both handlers wrap that body in the standard
{"errors": […]} envelope, so the exception decides its own
representation but never the response shape.
Configuration
Configure renderers per media type under
Netlogix.WebApi.error.availableErrorHandlers. The shape of the
options entry mirrors Flow's own Neos.Flow.error.exceptionHandler
(defaultRenderingOptions, renderingGroups, …), so the values can be
copy-pasted between the two.
Netlogix: WebApi: error: availableErrorHandlers: 'application/vnd.api+json': className: 'Netlogix\WebApi\Error\JsonExceptionHandler' 'application/json': className: 'Netlogix\WebApi\Error\JsonExceptionHandler' '*': className: 'Neos\Flow\Error\ProductionExceptionHandler' options: defaultRenderingOptions: renderTechnicalDetails: false logException: true
- Keys are IANA media types; the request's
Acceptheader is negotiated against them, respecting q-values and*/*ranges. - The special key
*is the fallback used when no configured media type matches the request's preferences. If*is missing and nothing else matches, the exception escapes back to Flow'sset_exception_handlerchain. - The shipped
Configuration/Development/Settings.ExceptionHandler.yamlswaps every renderer for its debug counterpart:Neos\Flow\Error\DebugExceptionHandlerfor the*fallback andNetlogix\WebApi\Error\JsonDebugExceptionHandlerfor both JSON media types — mirroring how Flow itself replaces the production handler with the debug variant in Development.
Logging
Logging is delegated entirely to the resolved Flow ExceptionHandler
(logException in its rendering options drives ThrowableStorage); the
middleware itself does not log.
netlogix/webapi 适用场景与选型建议
netlogix/webapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 305.07k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 netlogix/webapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 netlogix/webapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 305.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-29