magedin / module-enhanced-api-search
增强 Magento 2 API 搜索
dev-master
2021-12-15 16:07 UTC
Requires
- magento/framework: *
- magento/module-webapi: *
This package is auto-updated.
Last update: 2024-09-15 21:49:08 UTC
README
本模块引入了一种新的在 Magento 2 API 中搜索的方法。不是使用查询字符串,而是使用 JSON 格式的 body 创建您的 searchCriteria
参数。
这个模块是为了什么而创建的?
在 Magento 2 API 中进行典型的搜索是将所有参数放入查询字符串中,如下所示
curl -X GET https://my-magento2.com/rest/V1/orders/?searchCriteria[currentPage]=1&searchCriteria[filterGroups][0][filters][0][field]=increment_id&searchCriteria[filterGroups][0][filters][0][value]=610001259&searchCriteria[filterGroups][0][filters][0][conditionType]=eq
在 Postman 中构建此查询字符串如下
嗯,这可能会有些令人困惑,实际上,我总是忘记如何构建这些参数。
本模块允许您使用最简化的 URL
https://my-magento2.com/rest/V1/orders/
以下 body 参数
{ "searchCriteria": { "pageSize": 20, "currentPage": 1, "filterGroups": [ { "filters": [ { "conditionType": "eq", "field": "increment_id", "value": "000000002" } ] } ] } }
简单,对吧?
等等!GET 请求中的 Body 参数?
是的,我理解这可能有些奇怪,可能会让我们的大脑有些困惑,甚至可能和缓存系统等问题有关,例如,但模块本身非常简单,因此没有必要这样做。如果它符合您的需求,请自由使用,无需任何费用。
但如果您对规则非常严格,您不需要使用它。
参考:https://www.rfc-editor.org/rfc/rfc2616