I have created a custom rest api module. When i am using GET method it’s working fine. But when i am trying to use POST method it giving below error
Request does not match any route.
Does anyone have any idea why it is not working?
My webapi.xml
Second method (GET) working but First method (POST) not working
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/test/info" method="POST">
<service class="BwipApiEndpointsApiCustomInterface" method="info"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/test/data" method="GET">
<service class="BwipApiEndpointsApiCustomInterface" method="data"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
My di.xml file
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="BwipApiEndpointsApiCustomInterface" type="BwipApiEndpointsModelApiCustom"/>
</config>
Interface file
interface CustomInterface{
/**
* GET for Post api
* @param string $value
* @return string
*/
public function info();
/**
* GET for Post api
* @param string $value
* @return string
*/
public function data();
}
My Model
<?php
namespace BwipApiEndpointsModelApi;
use MagentoFrameworkExceptionInputException;
use MagentoFrameworkExceptionNoSuchEntityException;
use MagentoFrameworkAppRequestInterface;
use BwipApiEndpointsApiCustomInterface;
class Custom implements CustomInterface
{
/**
* Returns greeting message to user
*
* @api
* @param string $name User name.
* @return string Greeting message with users name.
*/
protected $request;
public function __construct(
RequestInterface $request,
array $data = []
){
$this->request = $request;
}
public function info(){
$post= $this->request->getPost();
$info[] = array('message' => 'POST Working.', 'status'=> 0);
return $info;
}
public function data(){
$post= $this->request->getPost();
$info[] = array('message' => 'GET Working.', 'status'=> 0);
return $info;
}
}
Thanks in advance.