gossamer/response
Types
pub type ResponseInit {
Headers(headers.Headers)
Status(http_status.HttpStatus)
StatusText(String)
}
Constructors
-
Headers(headers.Headers) -
Status(http_status.HttpStatus) -
StatusText(String)
Values
pub fn array_buffer(
of response: Response,
) -> promise.Promise(
Result(array_buffer.ArrayBuffer, js_error.JsError),
)
Reads the response body as an ArrayBuffer. Returns an error if the body
has already been consumed or cannot be read.
pub fn blob(
of response: Response,
) -> promise.Promise(Result(blob.Blob, js_error.JsError))
Reads the response body as a Blob. Returns an error if the body has
already been consumed or cannot be read.
pub fn body(
of response: Response,
) -> Result(
readable_stream.ReadableStream(uint8_array.Uint8Array),
Nil,
)
The response body as a ReadableStream. Returns an error if the response
has no body.
pub fn bytes(
of response: Response,
) -> promise.Promise(
Result(uint8_array.Uint8Array, js_error.JsError),
)
Reads the response body as a Uint8Array. Returns an error if the body
has already been consumed or cannot be read.
pub fn clone(
response: Response,
) -> Result(Response, js_error.JsError)
Creates a clone of the response. Returns an error if the body has already been consumed or is locked to a reader.
pub fn error() -> Response
Creates a network error response — the kind returned by fetch when a
request cannot complete.
pub fn form_data(
of response: Response,
) -> promise.Promise(Result(form_data.FormData, js_error.JsError))
Reads the response body as FormData. Returns an error if the body has
already been consumed or the Content-Type is not multipart/form-data
or application/x-www-form-urlencoded.
pub fn from_blob_with(
body: blob.Blob,
with init: List(ResponseInit),
) -> Result(Response, js_error.JsError)
Creates a Response with a Blob body and init options. Returns an
error if init contains a status outside 200–599 or an invalid status
text.
pub fn from_buffer(body: array_buffer.ArrayBuffer) -> Response
Creates a Response with an ArrayBuffer body.
pub fn from_buffer_with(
body: array_buffer.ArrayBuffer,
with init: List(ResponseInit),
) -> Result(Response, js_error.JsError)
Creates a Response with an ArrayBuffer body and init options.
Returns an error if init contains a status outside 200–599 or an
invalid status text.
pub fn from_bytes(body: uint8_array.Uint8Array) -> Response
Creates a Response with a Uint8Array body.
pub fn from_bytes_with(
body: uint8_array.Uint8Array,
with init: List(ResponseInit),
) -> Result(Response, js_error.JsError)
Creates a Response with a Uint8Array body and init options. Returns
an error if init contains a status outside 200–599 or an invalid
status text.
pub fn from_form_data(body: form_data.FormData) -> Response
Creates a Response with a FormData body. The content type is set
to multipart/form-data automatically.
pub fn from_form_data_with(
body: form_data.FormData,
with init: List(ResponseInit),
) -> Result(Response, js_error.JsError)
Creates a Response with a FormData body and init options. Returns
an error if init contains a status outside 200–599 or an invalid
status text.
pub fn from_json(data: a) -> Result(Response, js_error.JsError)
Creates a Response with data serialized as JSON. Returns an error
if data contains cycles or non-serializable values.
pub fn from_json_with(
data: a,
with init: List(ResponseInit),
) -> Result(Response, js_error.JsError)
Creates a Response with data serialized as JSON and init options.
Returns an error if data is not serializable, or init contains a
status outside 200–599 or an invalid status text.
pub fn from_params(
body: url_search_params.URLSearchParams,
) -> Response
Creates a Response with a URLSearchParams body. The content type
is set to application/x-www-form-urlencoded automatically.
pub fn from_params_with(
body: url_search_params.URLSearchParams,
with init: List(ResponseInit),
) -> Result(Response, js_error.JsError)
Creates a Response with a URLSearchParams body and init options.
Returns an error if init contains a status outside 200–599 or an
invalid status text.
pub fn from_stream(
body: readable_stream.ReadableStream(uint8_array.Uint8Array),
) -> Result(Response, js_error.JsError)
Creates a Response with a ReadableStream body. Returns an error if
the stream is locked to a reader or has been disturbed.
pub fn from_stream_with(
body: readable_stream.ReadableStream(uint8_array.Uint8Array),
with init: List(ResponseInit),
) -> Result(Response, js_error.JsError)
Creates a Response with a ReadableStream body and init options.
Returns an error if the stream is locked or has been disturbed, or
init contains a status outside 200–599 or an invalid status text.
pub fn from_string_with(
body: String,
with init: List(ResponseInit),
) -> Result(Response, js_error.JsError)
Creates a Response with a string body and init options. Returns an
error if init contains a status outside 200–599 or an invalid status
text.
pub fn headers(of response: Response) -> headers.Headers
pub fn is_body_used(response: Response) -> Bool
pub fn is_ok(response: Response) -> Bool
Checks whether the status is in the 200–299 range.
pub fn is_redirected(response: Response) -> Bool
Checks whether the response is the result of following a redirect.
pub fn json(
of response: Response,
) -> promise.Promise(Result(dynamic.Dynamic, js_error.JsError))
Reads the response body and parses it as JSON. Returns an error if the body has already been consumed or the content is not valid JSON.
pub fn redirect(
url: String,
) -> Result(Response, js_error.JsError)
Creates a redirect response to url with status 302 Found. Returns an
error if url is not a valid URL.
pub fn redirect_url(url: url.URL) -> Response
Creates a redirect response to url with status 302 Found.
pub fn redirect_url_with_status(
url: url.URL,
status status: http_status.HttpStatus,
) -> Result(Response, js_error.JsError)
Creates a redirect response to url with the given status. Returns an
error if status is not a redirect status (3xx).
pub fn redirect_with_status(
url: String,
status status: http_status.HttpStatus,
) -> Result(Response, js_error.JsError)
Creates a redirect response to url with the given status. Returns an
error if url is not a valid URL or status is not a redirect status
(3xx).
Examples
response.redirect_with_status(
"https://example.com/new",
status: http_status.MovedPermanently,
)
pub fn status(of response: Response) -> http_status.HttpStatus
The HTTP status of the response. Well-known codes return a matching
HttpStatus variant; other codes return http_status.Other(code).
pub fn status_text(of response: Response) -> String
pub fn text(
of response: Response,
) -> promise.Promise(Result(String, js_error.JsError))
Reads the response body as text. Returns an error if the body has already been consumed or cannot be read.
pub fn type_(of response: Response) -> response_type.ResponseType