ResponseUtility
in package
Utility to generate Response instances.
All responses created by methods in this class has
Cache-Control: no-store
and Pragma: no-cache
.
Table of Contents
Methods
- badRequest() : Response
- Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "400 Bad Request".
- forbidden() : Response
- Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "403 Forbidden".
- internalServerError() : Response
- Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "500 Internal Server Error".
- location() : Response
- Create a response having the given "Location" header value with the HTTP status code "30 Found".
- noContent() : Response
- Create a response with the HTTP status code "204 No Content".
- notFound() : Response
- Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "404 Not Found".
- okHtml() : Response
- Create a response having the given content formatted in "text/html;charset=UTF-8" with the HTTP status code "200 OK".
- okJavaScript() : Response
- Create a response having the given content formatted in "application/javascript;charset=UTF-8" with the HTTP status code "200 OK".
- okJson() : Response
- Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "200 OK".
- okJwt() : Response
- Create a response having the given content formatted in "application/jwt" with the HTTP status code "200 OK".
- unauthorized() : Response
- Create a response with the HTTP status code "401 Unauthorized" and optionally with JSON.
- wwwAuthenticate() : Response
- Create a response with a WWW-Authenticate header.
Methods
badRequest()
Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "400 Bad Request".
public
static badRequest(string $content) : Response
Parameters
- $content : string
-
The content formatted in
application/json;charset=UTF-8
.
Return values
Response —An HTTP response with "400 Bad Request" and JSON.
forbidden()
Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "403 Forbidden".
public
static forbidden(string $content) : Response
Parameters
- $content : string
-
The content formatted in
application/json;charset=UTF-8
.
Return values
Response —An HTTP response with "403 Forbidden" and JSON.
internalServerError()
Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "500 Internal Server Error".
public
static internalServerError(string $content) : Response
Parameters
- $content : string
-
The content formatted in
application/json;charset=UTF-8
.
Return values
Response —An HTTP response with "500 Internal Server Error" and JSON.
location()
Create a response having the given "Location" header value with the HTTP status code "30 Found".
public
static location(string $location) : Response
Parameters
- $location : string
-
The value of the
Location
header.
Return values
Response —An HTTP response with "302 Found" and a Location
header.
noContent()
Create a response with the HTTP status code "204 No Content".
public
static noContent() : Response
Return values
Response —An HTTP response with "204 No Content".
notFound()
Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "404 Not Found".
public
static notFound(string $content) : Response
Parameters
- $content : string
-
The content formatted in
application/json;charset=UTF-8
.
Return values
Response —An HTTP response with "404 Not Found" and JSON.
okHtml()
Create a response having the given content formatted in "text/html;charset=UTF-8" with the HTTP status code "200 OK".
public
static okHtml(string $content) : Response
Parameters
- $content : string
-
The content formatted in
text/html;charset=UTF-8
.
Return values
Response —An HTTP response with "200 OK" and HTML.
okJavaScript()
Create a response having the given content formatted in "application/javascript;charset=UTF-8" with the HTTP status code "200 OK".
public
static okJavaScript(string $content) : Response
Parameters
- $content : string
-
The content formatted in
application/javascript;charset=UTF-8
.
Return values
Response —An HTTP response with "200 OK" and JavaScript.
okJson()
Create a response having the given content formatted in "application/json;charset=UTF-8" with the HTTP status code "200 OK".
public
static okJson(string $content) : Response
Parameters
- $content : string
-
The content formatted in
application/json;charset=UTF-8
.
Return values
Response —An HTTP response with "200 OK" and JSON.
okJwt()
Create a response having the given content formatted in "application/jwt" with the HTTP status code "200 OK".
public
static okJwt(string $content) : Response
Parameters
- $content : string
-
The content formatted in
application/jwt
.
Return values
Response —An HTTP response with "200 OK" and JWT.
unauthorized()
Create a response with the HTTP status code "401 Unauthorized" and optionally with JSON.
public
static unauthorized(string $challenge[, $content = null ]) : Response
Parameters
- $challenge : string
-
The value of the
WWW-Authenticate
header. - $content : = null
-
The content formatted in `application/json;charset=UTF-8'. This parameter is optional.
Return values
Response —An HTTP response with "401 Unauthorized" and optionally with JSON.
wwwAuthenticate()
Create a response with a WWW-Authenticate header.
public
static wwwAuthenticate(int $statusCode, string $challenge[, string $content = null ]) : Response
Parameters
- $statusCode : int
-
HTTP status code of the response.
- $challenge : string
-
The value of the
WWW-Authenticate
header. - $content : string = null
-
The content formatted in `application/json;charset=UTF-8'. This parameter is optional.
Return values
Response —An HTTP response with the specified status code and a
WWW-Authenticate
header, and optionally with JSON.