Saya tidak mendapatkan hasil (id) saat menggunakan metode POST menggunakan url adalah rest / V1 / hello / test / 3
Saya telah mengikuti tautan ini Untuk Referensi Silakan Klik Di Sini
1) webapi.xml
<?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/hello/name/:name" method="GET">
<service class="Inchoo\Hello\Api\HelloInterface" method="name"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/hello/test/:test" method="POST">
<service class="Inchoo\Hello\Api\TestInterface" method="test"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
2) TestInterface.php
<?php
namespace Inchoo\Hello\Api;
interface TestInterface
{
/**
* Returns greeting message to user
*
* @api
* @param id $name Users id.
* @return id Greeting message with users id.
*/
public function test($id);
}
3) Test.php
<?php
namespace Inchoo\Hello\Model;
use Inchoo\Hello\Api\TestInterface;
class Test implements TestInterface
{
/**
* Returns greeting message to user
*
* @api
* @param string $name Users name.
* @return string Greeting message with users name.
*/
public function test($id) {
return "Hello How are you your id is:," .$id;
}
}
4) 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="Inchoo\Hello\Api\HelloInterface" type="Inchoo\Hello\Model\Hello" />
<preference for="Inchoo\Hello\Api\TestInterface" type="Inchoo\Hello\Model\Test" />
</config>
Sekarang saya membersihkan cache dan pagecache dan membuka aplikasi tukang pos dan menjaga url seperti http://10.0.0.33/nagarajuM2/rest/V1/hello/test/3
tetapi saya mendapatkan kesalahan.
Tolong bantu saya.