falcon/core
Types
pub type Config {
Body(OpaqueBody)
Headers(Pairs)
Queries(Pairs)
ClientOptions(hackney.Options)
}
Constructors
-
Body(OpaqueBody)
A string to use as the body of the request - not meant to be used directly, use
post
,put
, orpatch
instead, or if necessary,to_body
-
Headers(Pairs)
A list of headers to prepend to the request
-
Queries(Pairs)
A list of query parameters to append to the URL
-
ClientOptions(hackney.Options)
A list of options to pass to the underlying HTTP client to control things like timeouts and redirects
pub type FalconError {
URLParseError
InvalidUtf8Response
HackneyError(Dynamic)
RawDecodingError(dynamic.DecodeErrors)
JsonDecodingError(json.DecodeError)
}
Constructors
-
URLParseError
-
InvalidUtf8Response
-
HackneyError(Dynamic)
-
RawDecodingError(dynamic.DecodeErrors)
-
JsonDecodingError(json.DecodeError)
pub type FalconResponse(a) {
FalconResponse(status: Int, headers: Pairs, body: a)
}
Constructors
-
FalconResponse(status: Int, headers: Pairs, body: a)
This exists to prevent the body from being added manually to requests like Get and Delete which don’t support bodies. Since a user cannot create an OpaqueBody, they cannot add a body to a request that doesn’t support it
pub opaque type OpaqueBody
pub type ResultResponse(a) =
Result(FalconResponse(a), FalconError)
pub type Target(a) {
Json(Decoder(a))
Raw(Decoder(a))
}
Constructors
-
Json(Decoder(a))
-
Raw(Decoder(a))
Functions
pub fn append_path(url: Url, path: String) -> Url
pub fn delete(
to url: Url,
expecting target: Target(a),
options opts: List(Config),
) -> Result(FalconResponse(a), FalconError)
pub fn error_to_string(err: FalconError) -> String
Convert a FalconError to a string for display - some errors like HackneyError are not very helpful to the end user and are logged instead
pub fn extract_body(response: FalconResponse(a)) -> a
pub fn extract_headers(
response: FalconResponse(a),
) -> List(#(String, String))
pub fn extract_params(
opts: List(Config),
state: #(Request(String), List(HackneyOption)),
) -> #(Request(String), List(HackneyOption))
pub fn extract_status_code(response: FalconResponse(a)) -> Int
pub fn get(
to url: Url,
expecting target: Target(a),
options opts: List(Config),
) -> Result(FalconResponse(a), FalconError)
pub fn patch(
to url: Url,
body body: String,
expecting target: Target(a),
options opts: List(Config),
) -> Result(FalconResponse(a), FalconError)
pub fn post(
to url: Url,
body body: String,
expecting target: Target(a),
options opts: List(Config),
) -> Result(FalconResponse(a), FalconError)
pub fn put(
to url: Url,
body body: String,
expecting target: Target(a),
options opts: List(Config),
) -> Result(FalconResponse(a), FalconError)
pub fn send(
method method: Method,
url url: Url,
expecting decode: Target(a),
options opts: List(Config),
) -> Result(FalconResponse(a), FalconError)
Core function for sending requests, you would normally use the get
, post
, put
, patch
, or delete
functions instead
pub fn to_body(body: String) -> Config
Convert a string to an OpaqueBody - only use this if you are using the send
function directly
pub fn url_to_string(url: Url) -> String