I am building my own rest api in php for practice. I can evaluate the http code sent to my api (post,put,delete,get). But when I send out my response I really am just printing out a json. For example, I build a response in my api like this
public function actionTest()
{
$rtn=array("id":"3","name":"John");
print json_encode($rtn);
}
I am not manipulating the headers in anyway. From reading stackoverflow, I understand that I should be returning http response codes to match my api results. How can I build on my api and return the response codes. I just don't understand how I can do it because right now I am just printing out a json.
I am not asking which codes to return. I just want to know how to return codes in general.