I have created rest api it's not working Could you please suggest me where i went wrong?

Error: main.CRITICAL: exception 'ReflectionException' with message 'Report ID: webapi-560e33c7e2c45; Message: Class name does not exist'

my code is:


modules' => 
  array (  
    'Learning_Test' => 1,



namespace Learning\Test\Api;

interface WebserviceInterface

     * @param $name
     * @return mixed
    public function say($name);


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Learning\Test\Api\WebserviceInterface" type="Learning\Test\Model\Webservice" />


<?xml version="1.0"?>

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">

    <!-- Example: curl -->
    <route url="/V1/webservice/say/:name" method="GET">
        <service class="Learning\Test\Api\WebserviceInterface" method="say"/>
            <resource ref="anonymous"/>



namespace Learning\Test\Model;
use Learning\Test\Api\WebserviceInterface;

class Webservice implements WebserviceInterface

     * @param $name
     * @return string
    public function say($name) {
        return ' Welcome to ' . $name;

Could you please suggest me where I went wrong?


  • your file name is app/code/Learning/Test/Model/Webservice.php but your class name is VLC\Test\Model\Webservice. is this a typo in the post , or this is the actual issue? – Marius Oct 2 '15 at 7:39
  • @Marius, it's Typing mistake now I have updated. – Bojjaiah Oct 2 '15 at 7:47
  • @Marius, please look my answer and confirm? – Bojjaiah Oct 2 '15 at 9:55

Finally I have achieved by adding below code in WebserviceInterface.php

     * @param string $name of the param.
     * @return mixed|string of the param Value.

    public function say($name);

I'm observing that when i have added above function with comments then it's working fine otherwise it's not working.

I don't know the comment is the key for the function to work?

If some one knows please let me know?

  • It must add type of value "int|string" ... – St3phan Jun 18 '19 at 22:29

Interface class is used to filter incoming and outgoing values. Based on phpdoc magento will prepare values to get from the request and pass to the model that handles it. Also response will also be filtered based on the phpdoc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.