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' }) %}
Copied!
The above call will return a response with a application/json
content type.
{ "foo": "bar" }
Copied!
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) %}
Copied!
You may also pass custom headers as the third argument.
{% do response('Bad Request', 400, {'X-Failure-Reason': 'Not wearing shoes'}) %}
Copied!