response()

response()

Twig Function

The response() function overrides the page from being displayed and returns a response, usually in the form of JSON payload.

{% do response({ foo: 'bar' }) %}

The above call will return a response with a application/json content type.

{
    "foo": "bar"
}

By default a status code of 200 will be used. You may specify any status code by passing it as the second argument.

{% do response('Bad Request', 400) %}

You may also pass custom headers as the third argument.

{% do response('Bad Request', 400, {'X-Failure-Reason': 'Not wearing shoes'}) %}

# See Also

On This Page