1

I have created many Api's (both GET and POST) but now I want to create the custom search API with different URL Structure (all the params after ?).

I can create the search API in below URL formate..

/V1/getSearch/vendor/:vendArea/type/:typeId

but I want to achieve the same with below given formate..

/V1/getSearch/?vendor=bangalore&type=2

Any body have idea to get this formate ?

1 Answer 1

0

finally achieved this..

there is nothing special we need to define in XML or Interface we simply need construct the instance of Magento\Framework\App\Request\Http into the class where we are making our method.

for example:

function __construct( Magento\Framework\App\Request\Http $request) {

 $this->_request                 = $request;

}

public function getParam(){

 $filter = $this->_request->getParam('filter');

}

now filter will have the filter parameter value you passed in the API URL..

Hope this will help.

2
  • can you post complete code.
    – Alok Singh
    Commented Aug 28, 2018 at 10:59
  • @AlokSingh in your API method you can get do the above thing, alternatively you can use RequestInterface to ge the above data. Commented Aug 30, 2018 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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