Hello Dev, 

In this tutorial, we will learn Laravel Check If Api Request Code Example.

These days applications only serve HTML or JSON right? you can use the expected Json methods to quickly determine if the incoming request expects a JSON response

Follow this step by step guide below, 

if (Request::wantsJson()) {
    // return JSON-formatted response
} else {
    // return HTML response

May this example help you.