Only JSON outputs


#1

Hello,

I am building an API with Slim framework and I would be interested in only having JSON outputs, not only for routes but for every error or message that the framework would throw. Is this possible?

Thank you.


#2

This happens by default if the client sets their Accept header to application/json.

Otherwise, you can override the error handling to do force it yourself.


#3

That’s great.

Thanks.


#4

What if I wish to force JSON output ?


#5

I think I found the solution by using withJson() !

Thanks.