Вопрос

I would like to return code 201 Created in some cases in my API. How can I do this?

Это было полезно?

Решение

I discovered accidentally that adding @status «code» to the method documentation alters the success response code, as follows:

/**
 * Creates a post.
 * @status 201
 *
 * @param string $title {@from body} Post title
 * @param string $message {@from body} Post body
 */
protected function post($title, $message) {
    return Posts::create(compact('title', 'message'));
}

Другие советы

Disclaimer - As I have been informed not the correct way to do it for restler but in general with php for custom status messages this is what you would do:

User header

header("HTTP/1.0 201 Created");
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top