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

Ashish Raj
1,3752 gold badges15 silver badges32 bronze badges
asked Nov 28, 2017 at 6:41
1
  • Why do you want to distinct these two? Commented 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?

answered Nov 28, 2017 at 10:10
1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.