0

I am writing Rest api end point for GET method and testing the same in postman client. By default there is no Header for encoding technique called utf-8. I want to send it in Response headers manually. So I tried like below:

$response = new ResourceResponse($newsfeed, 200);
$response->headers->set('charset', 'utf-8');

After this I got this in postman Headers like :Charset: utf-8.

I am just wondering is this right way to set or is there any alternative efficient way to handle it? Can anyone help me on this?

  • Yes, this is the right way. If you want to set a header for all responses of a specific type then use an event subscriber, see drupal.stackexchange.com/a/262716/47547 – 4k4 May 8 at 11:23
  • Thank you @4k4, I am just wondering why its not added by default to Content-Type: application/json; charset=utf-8 like this. Am i missing something while sending response? – Suraj May 8 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.