0

I have recently started using Slim to make an API but I have been unsuccessful in all my attempts. My main problem is that I am not able to set the HTTP status code using the withStatus method on the Response object. I always receive a 200 OK when I test with Postman and browser.

I seem to have figured out where the problem might be. In my project, I have my web application which is done without any frameworks in the root. I also have an API built using slim in a subdirectory /api/v1/index.php. When I tested with the slim API in the root, the status codes seem to be changing according to what I set. This leads me to believe that the issue is with me putting the API in a subfolder.

Is there anyway I can edit the .htaccess or apache config to send http codes from my slim application rather than my apache server which seems to be overriding my status code to 200 OK?

Raj
  • 22,346
  • 14
  • 99
  • 142
  • which URL returns 200 and which returns the expected code? – Raj Jan 04 '17 at 10:56
  • If `Response` implements Psr interface then note that `withStatus()` (and other methods) won't change existing response object, but produce a new one with this single change (mutated clone). – shudder Jan 04 '17 at 11:29
  • you probably are not returning the response object from your Controller / Action – geggleto Jan 04 '17 at 17:35
  • I am return the clone of the response object in both cases as the documentation says. My problem is that it only works when I have the slim index.php in the document root as compared to in a sub-directory. When the slim index.php is in the document root, everything is working. – Chaitanya Pilaka Jan 04 '17 at 19:23

0 Answers0