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

1
  • Why do you want to distinct these two? Nov 28, 2017 at 8:04

1 Answer 1

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?

1

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.