1

I am using the following code to return a Json encoded response from a function.

return response()->json($returnArray);

However the reponse is as follow and include the HTTP headers:

Cache-Control: no-cache, private
Content-Type:  application/json
Date:          Mon, 23 Oct 2017 15:34:59 GMT

{"status":"success"}  

How can I set the response so the headers are not included and only include the JSON?

{"status":"success"} 
1
  • 1
    Is there is any specific reason not to send headers with response? Without headers client might not know what to do with the data. Commented Oct 23, 2017 at 15:58

2 Answers 2

1

I had the some problem as you.

In my case problem was in string return type hinting in method.

Example:

public function getJson(): string{
    return response()->json(['foo' => 'bar']);
}

So, I replaced string to JsonResponse and that's all - problem solved.

Maybe would helps someone.

Sign up to request clarification or add additional context in comments.

Comments

0

How about:

return response()->toJson([
    'status' => 'success',
], 201);

or:

return Response::json(['data' => $array],201);

Comments

Your Answer

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.