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 standard JavaScript Response
.
pub type JsResponse
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)
}
Constructors
-
Text(String)
-
Bits(BitArray)
File uploaded from the client.
pub type UploadedFile {
UploadedFile(file_name: String, path: String)
}
Constructors
-
UploadedFile(file_name: String, path: String)
Arguments
-
file_name
The name that was given to the file in the form. This is user input and should not be trusted.
-
path
The location of the file on the server. This is a temporary file and will be deleted when the request has finished being handled.
-
Functions
pub fn read_bits(
body: RequestBody,
) -> Promise(Result(BitArray, Nil))
Read a request body as a BitArray.
pub fn read_form(
body: RequestBody,
) -> Promise(Result(FormData, Nil))
Read a request body as FormData
.
pub fn read_json(
body: RequestBody,
) -> Promise(Result(Dynamic, Nil))
Read a request body as JSON, returning a
Dynamic
value
which can then be decoded with gleam_json
.
pub fn read_text(
body: RequestBody,
) -> Promise(Result(String, Nil))
Read a request body as text.
pub fn translate_request(req: JsRequest) -> Request(RequestBody)
pub fn translate_response(
res: Response(ResponseBody),
) -> JsResponse
Translates a Gleam Response
into a JsResponse
.