I need to get a link of this kindhttp://localhost/Magento2/rest I have a code by which I get base_url:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$baseUrl = $storeManager->getStore()->getBaseUrl

So i get http://localhost/Magento2/,but i need http://localhost/Magento2/rest.Help find a solution, please

3 Answers 3


I don't think this is available programmatically, but you can manually append 'index.php/rest/V1/' to the base URL as this should not ever change.


This one would work for my case.

/** @var \Magento\Framework\Url $url */
$url = $objectManager->get(\Magento\Framework\Url::class);

    '_path' => 'enquiry',
    '_secure' => true,
    '_direct' => 'rest/V1/link-to-resource',
    '_query' => [
        'paramA' => "XXXX",
        'paramB' => "XXXXX"

Try with Below solution:

* @urlBuilder \Magento\Framework\UrlInterface


Your Answer

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

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