conversation
Types
Data parsed from form sent in a request’s body.
pub type FormData {
FormData(
values: List(#(String, String)),
files: List(#(String, UploadedFile)),
)
}
Constructors
-
FormData( values: List(#(String, String)), files: List(#(String, UploadedFile)), )
Arguments
-
values
String values of the form’s fields, sorted alphabetically.
-
files
Uploaded files, sorted alphabetically by file name.
-
A JavaScript ReadableStream
.
pub type JsReadableStream
A standard JavaScript Response
.
pub type JsResponse
Error type representing possible errors produced by body reading functions.
pub type ReadError {
AlreadyRead
ParseError(message: String)
ReadError(message: String)
}
Constructors
-
AlreadyRead
Request body has already been read.
-
ParseError(message: String)
Failed to parse JSON or form body.
-
ReadError(message: String)
Failed to read request body.
The body of an incoming request. It must be read with functions like
read_text
, and can only be read once.
pub type RequestBody
Body type for an outgoing response.
import gleam/http/response
import conversation.{Text}
response.new(200)
|> response.set_body(Text("Hello, world!"))
pub type ResponseBody {
Text(String)
Bits(BitArray)
Stream(JsReadableStream)
}
Constructors
-
Text(String)
A text body.
-
Bits(BitArray)
A BitArray body.
-
Stream(JsReadableStream)
A
JsReadableStream
body. This is useful for sending files without reading them into memory. (For example: using theDeno.openSync(path).readable
API.)
File uploaded from the client. Conversation does not currently support reading the file’s contents.
pub type UploadedFile {
UploadedFile(file_name: String)
}
Constructors
-
UploadedFile(file_name: String)
Arguments
-
file_name
The name that was given to the file in the form. This is user input and should not be trusted.
-
Functions
pub fn read_bits(
body: RequestBody,
) -> Promise(Result(BitArray, ReadError))
Read a request body as a BitArray.
pub fn read_form(
body: RequestBody,
) -> Promise(Result(FormData, ReadError))
Read a request body as FormData
. If the formdata cannot be
parsed, a ParseError
is returned.
pub fn read_json(
body: RequestBody,
) -> Promise(Result(Dynamic, ReadError))
Read a request body as JSON, returning a
Dynamic
value
which can then be decoded with gleam_json
.
If the JSON cannot be parsed, a ParseError
is returned.
pub fn read_text(
body: RequestBody,
) -> Promise(Result(String, ReadError))
Read a request body as text.
pub fn to_gleam_request(req: JsRequest) -> Request(RequestBody)
pub fn to_js_request(req: Request(RequestBody)) -> JsRequest
pub fn to_js_response(res: Response(ResponseBody)) -> JsResponse
Convert a Gleam Response
into a JsResponse
.