How to determine where a request is coming from in a REST api

后端 未结 4 866
离开以前
离开以前 2021-02-07 07:12

I have an RESTful API with controllers that should return a JSON response when is being hit by my android application and a \"view\" when it\'s being hit by a web browser. I\'m

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 07:41

    Use this Way. you can simply identify URL being call form ( Web or API )

    Controller code

    if ( Request::capture()->expectsJson()  )
         {  return "API Method";  }
         else
         {  return "Web Method";     }
    

    Route Code

    For api.php Route::post("category","CategoryController@index");

    For Web.php Route::get("category","CategoryController@index");

提交回复
热议问题