Module http/http
HTTP core types — methods, headers, requests, and responses.
Types
Standard HTTP request methods.
Variants
| Variant | Fields | Description |
|---|---|---|
GET | ||
POST | ||
PUT | ||
DELETE | ||
HEAD | ||
PATCH |
Trait Implementations
impl(HttpMethod, ToString(...))
to_string : (self ->
match(self,
.GET => `GET`,
.POST => `POST`,
.PUT => `PUT`,
.DELETE => `DELETE`,
.HEAD => `HEAD`,
.PATCH => `PATCH`
)
)An HTTP header as a name-value pair.
Fields
| Name | Type | Description |
|---|---|---|
name | String | |
value | String |
impl(HttpHeader, ...)
new : (HttpHeader) fn(name : String, value : String) -> HttpHeaderCreate a new response with the given status code and text.
Parameters
| Name | Type | Notes |
|---|---|---|
name | String | |
value | String |
Returns: HttpHeader
An HTTP request with method, path, headers, and optional body.
Fields
| Name | Type | Description |
|---|---|---|
method | HttpMethod | |
path | String | |
headers | ArrayList(HttpHeader) | |
body | String |
impl(HttpRequest, ...)
new : (HttpRequest) fn(method : HttpMethod, path : String) -> HttpRequestCreate a new response with the given status code and text.
Parameters
| Name | Type | Notes |
|---|---|---|
method | HttpMethod | |
path | String |
Returns: HttpRequest
header : (HttpRequest) fn(self : HttpRequest, name : String, value : String) -> HttpRequestAdd a header and return the request (builder pattern).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest | |
name | String | |
value | String |
Returns: HttpRequest
with_body : (HttpRequest) fn(self : HttpRequest, body : String) -> HttpRequestSet the request body and return the request (builder pattern).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest | |
body | String |
Returns: HttpRequest
set_host : (HttpRequest) fn(self : HttpRequest, host : String) -> unitset_header : (HttpRequest) fn(self : HttpRequest, name : String, value : String) -> unitAppend a header to the request.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest | |
name | String | |
value | String |
Returns: unit
set_body : (HttpRequest) fn(self : HttpRequest, body : String) -> unitto_string : (HttpRequest) fn(self : HttpRequest) -> StringSerialize the request to an HTTP/1.1 wire-format string.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest |
Returns: String
An HTTP response with status code, headers, and body.
Fields
| Name | Type | Description |
|---|---|---|
status_code | i32 | |
status_text | String | |
headers | ArrayList(HttpHeader) | |
body | String |
impl(HttpResponse, ...)
new : (HttpResponse) fn(status_code : i32, status_text : String) -> HttpResponseCreate a new response with the given status code and text.
Parameters
| Name | Type | Notes |
|---|---|---|
status_code | i32 | |
status_text | String |
Returns: HttpResponse
get_header : (HttpResponse) fn(self : HttpResponse, name : String) -> Option(String)Look up a header value by name (case-insensitive).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse | |
name | String |
is_ok : (HttpResponse) fn(self : HttpResponse) -> boolReturn true if the status code is in the 2xx range.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse |
Returns: bool
is_redirect : (HttpResponse) fn(self : HttpResponse) -> boolReturn true if the status code is in the 3xx range.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse |
Returns: bool
is_error : (HttpResponse) fn(self : HttpResponse) -> boolReturn true if the status code is 4xx or higher.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse |
Returns: bool
Functions
Parse a raw HTTP response string into an HttpResponse.
Parameters
| Name | Type | Notes |
|---|---|---|
raw | String |
Returns: Result(HttpResponse, String)
Return the standard status text for an HTTP status code.
Parameters
| Name | Type | Notes |
|---|---|---|
code | i32 |
Returns: String