Response interface from PSR does not include withJson() method, which is run on it in closure.
withJson() is just implemented in the Slim response for convenience and has to be implemented yourself in some way when you want to use a different PSR7 implementation.
Thats the reason for this note on the doc-block:
Okey, but still - it's not in the interface so IDEs and Rich text editors will throw a warning, why don't you create SlimResponseInterface that will extends PSR7 implementation?
@archi-tektur
鈥hy don't you create SlimResponseInterface that will extends PSR7 implementation?
This would be against the idea of PSR and interoperability.
Suggestion: create a separate JsonResponse class which implements the PSR-7 interface for response.
(Compare with zend-diactoros and the custom responses: https://docs.zendframework.com/zend-diactoros/v2/custom-responses/)
Another option is to type hint to a Slim\Http\Response if you know that it will always be one in your application.
Okay, thanks, to be closed then
Closing as per @archi-tektur's request
Most helpful comment
@archi-tektur
This would be against the idea of PSR and interoperability.
Suggestion: create a separate
JsonResponseclass which implements the PSR-7 interface for response.(Compare with zend-diactoros and the custom responses: https://docs.zendframework.com/zend-diactoros/v2/custom-responses/)