Change response code to 201 in Restler

85 Views Asked by At

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.

1

There are 1 best solutions below

1
Arul Kumaran On

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