0

I have created a module for checkout payment methods event. But I need to check request is getting from web or rest API.

I mean something like:

if(request from rest API)
{ 
    echo "REST API"; 
} 
else 
{ 
    echo "WEB";
} 

Please Help me

  • Why do you want to distinct these two? – Bartosz Herba Nov 28 '17 at 8:04
0

You can use Magento\Framework\App\State::getAreadCode() to check the request is from web or API. If the request is from API, this will return "webapi_rest" or "webapi_soap". If the request is from web, this will return "frontend".

Ref: Magento2: How to check if request is from Web Service?

|improve this answer|||||

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.