0

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

4 Answers 4

0

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.

1

This one would work for my case.

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

$url->getUrl(
null,
[
    '_path' => 'enquiry',
    '_secure' => true,
    '_direct' => 'rest/V1/link-to-resource',
    '_query' => [
        'paramA' => "XXXX",
        'paramB' => "XXXXX"
    ]
]
0

Try with Below solution:

/**
* @urlBuilder \Magento\Framework\UrlInterface
*/

$urlBuilder->getUrl("rest/*/V1/");  
0

Try with Below solution:

$urlBuilder = $om->get(\Magento\Framework\UrlInterface::class);
$urlBuilder->getCurrentUrl();

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.