laravel-api-generator icon indicating copy to clipboard operation
laravel-api-generator copied to clipboard

sendResponse should has encoding parameters

Open zhekaus opened this issue 9 years ago • 3 comments

I think it will be much more convenient if you add some lines to the AppBaseController->sendResponse method allowing seeing encoded json properly:

public function sendResponse($result, $message)
{
    $headers = ['Content-type'=> 'application/json; charset=utf-8'];

    return Response::json($this->makeResponse($result, $message), 200, $headers, JSON_UNESCAPED_UNICODE);
}

I’d like to be able to easily read the output instead of "...\u043a\u0440\u044b\u043b\u0430\u0442\u044b\u0445 \u0444\u0440\u0430\u0437..."

zhekaus avatar Aug 17 '15 23:08 zhekaus

@zhekaus why you are getting output like,

"...\u043a\u0440\u044b\u043b\u0430\u0442\u044b\u0445 \u0444\u0440\u0430\u0437..." ?

mitulgolakiya avatar Aug 20 '15 04:08 mitulgolakiya

Because it isn’t English but Cyrillic (Russian) in utf8 encoding. If I add headers parameter and JSON_UNESCAPED_UNICODE option, I’ll see Russian text.

zhekaus avatar Aug 20 '15 06:08 zhekaus

Actually, we are already using Response::json to send a response and it's not a general requirement. so can not add it as of now. But it you want to do so, then you can do it by following steps:

  1. Create your own AppBaseController with the copy of package one
  2. Publish Templates
  3. Modify /resources/api-generator-templates/api/Controller.stub & /resources/api-generator-templates/scaffold/Controller.stub to use your AppBaseController instead of package one. (Don't forget to delete the templates which you are not using)

mitulgolakiya avatar Sep 02 '15 03:09 mitulgolakiya