I have create request data need to save the data in the custom table using rest API endpoints


You have to create a rest API endpoint. Your route has to call a service with a method. Then, make a preference for your API Class to your Model. Then in your Model save your data

    <route url="/V1/products" method="POST">
        <service class="Magento\Catalog\Api\ProductRepositoryInterface" method="save"/>
            <resource ref="Magento_Catalog::products" />

To illustrate a bit, /V1/products would be your route URL. With this route, we call the service Magento\Catalog\Api\ProductRepositoryInterface pointing on the save() method. In the di.xml file you make your preference:

   <preference for="Magento\Catalog\Api\ProductRepositoryInterface" type="Magento\Catalog\Model\ProductRepository" />

And from your Model , you do what you need. Hope it helps.

| improve this answer | |
  • I am not getting the response data in the file. how to get response data – Divya Oct 17 '19 at 12:24

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.