Inside of a method how can I dynamically change the response code to 201? I know for something like a 204 I can just throw a RestException of that, but with a 201 I still need to return data.
You can use @status
comment for this purpose.
/**
* @status 201
*
* @param string $name {@from body}
* @param string $email {@type email} {@from body}
*
* @return mixed
*/
function post($name, $email)
{
return $this->dp->insert(compact('name', 'email'));
}
You can see how it works on the documentation example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.