Search code examples
phprestler

How to return a custom HTTP code in a Restler request?


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


Solution

  • 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'));
    }