wubinworks/module-webapi
Composer 安装命令:
composer require wubinworks/module-webapi
包简介
[1] Add support for `application/wubinworks-x-www-form-urlencoded`. [2] Conditionally modifies JSON output behavior. See https://github.com/wubinworks/magento2-module-webapi
README 文档
README
(Only works for REST endpoints.)
This module is designed as a dependency for developing other modules.
1. Support for Content-Type: application/x-www-form-urlencoded
Magento WEBAPI_REST recognizes application/json, application/xml, application/xhtml+xml, text/xml Content-Type out of the box, any others will result in an error message like
"message": "Server cannot understand Content-Type HTTP header media type application/x-www-form-urlencoded"
However, application/x-www-form-urlencoded is commonly used in forms and many third part software could only POST this content type.
How to use?
Just make the request normally using Content-Type: application/x-www-form-urlencoded and add an additional custom header Use-Deprecated-Content-Type: 1.
Note: You MUST include the Use-Deprecated-Content-Type: 1 header in your request, otherwise it does not work!
2. Conditionally modifies JSON output behavior
When developing a service class(usually a file called someActionManagement.php in Model folder), if it returns an array like below,
return [
'code' => 0,
'message' => 'Success',
'data' => [
'customer_id' => 1
]
];
Magento encloses the returned data in an array parentheses and property names got stripped out.
Output:
[
0,
"Success",
{
"customer_id": 1
}
]
This may be not what you want.
If the service class returns
return [
'dummy' => [
'code' => 0,
'message' => 'Success',
'data' => [
'customer_id' => 1
]
]
];
the output becomes
[
{
"code": 0,
"message": "Success",
"data": {
"customer_id": 1
}
}
]
Note the outermost [], many third party software expects the output to be an object, though.
How to use?
Add 'type' => 'simple_array' in the output array, i.e.,
return [
'code' => 0,
'message' => 'Success',
'data' => [
'customer_id' => 1
],
'type' => 'simple_array' // Add this key-value pair
];
Then output will be
{
"code": 0,
"message": "Success",
"data": {
"customer_id": 1
}
}
Note: the JSON output will not have "type": "simple_array", it got removed!
Requirements
Only tested under Magento 2.4
Installation
composer require wubinworks/module-webapi
wubinworks/module-webapi 适用场景与选型建议
wubinworks/module-webapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 830 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wubinworks/module-webapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wubinworks/module-webapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 830
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: OSL-3.0
- 更新时间: 2023-09-22