Magento 2.3中的REST API版本控制(V1/V2/V3)
澄清在Magento 2.3中对自定义API实施版本控制 当前场景:Magento 2.3中的REST API版本控制(V1/V2/V3),rest,api,magento,magento2,magento-2.3,Rest,Api,Magento,Magento2,Magento 2.3,澄清在Magento 2.3中对自定义API实施版本控制 当前场景: 我们已经实现了带有一些功能的定制RESTAPI。 API规范: API: 方法:获取 预期情景 我们需要在第2版中使用相同的功能,只需稍作修改 API规范 API: 方法:获取 注意: 两个API端点服务方法应该是相同的 当前场景不应因处理预期场景而中断。这两个API都应该像我们期望的那样工作 希望下面的代码可以帮助参考 /app/code/Custom/Module/etc/webapi.xml
- 我们已经实现了带有一些功能的定制RESTAPI。
- API规范:
- API:
- 方法:获取
- API规范:
- 我们需要在第2版中使用相同的功能,只需稍作修改
- API规范
- API:
- 方法:获取
- API规范
- 两个API端点服务方法应该是相同的
- 当前场景不应因处理预期场景而中断。这两个API都应该像我们期望的那样工作
<?xml version="1.0" ?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/custom/module/list" method="GET">
<service class="Custom\Module\Api\StudentInterface" method="getList" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
</routes>
/app/code/Custom/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Custom\Module\Api\StudentInterface" type="Custom\Module\Service\StudentService"/>
</config>
/app/code/Custom/Module/Api/StudentInterface.php
<?php
namespace Custom\Module\Api;
interface StudentInterface
{
/**
* Get Student list
*
* @return array
*/
public function getList();
}
是的working@Jinesh,谢谢你的回复。它将如何工作?我需要做什么?你需要像你在工作中一样创建扩展question@Jinesh,您的意思是将扩展(API端点)复制为V2,并使用具有不同方法名称的相同服务。?是的,这是处理magento API的标准方法是的working@Jinesh,谢谢你的回复。它将如何工作?我需要做什么?你需要像你在工作中一样创建扩展question@Jinesh,您的意思是将扩展(API端点)复制为V2,并使用具有不同方法名称的相同服务。?是的,这是处理magento API的标准方法
<?php
namespace Custom\Module\Service;
class StudentService
{
/**
* {@inheritdoc}
*/
public function getList()
{
//To do get Student List
}
}