Skip to content
FutureBlitz

    Install

    Import std.net.http.client

    Body

    std.net.http.client

    struct

    Public Struct Body

    What a request sends: its bytes, and what they are, as its Content-Type header says unless the request's headers say it themselves. Panics for a contentType a header's value can't be, as Headers.Add does.

    Examples

    Local form = Body.Form({"name": "Ada Lovelace", "age": "36"})
    Expect(form.ContentType == "application/x-www-form-urlencoded")
    Expect(String.FromUtf8(form.Bytes) == "name=Ada%20Lovelace&age=36")
    Expect(Body.Text("hi").ContentType == "text/plain; charset=utf-8")

    std/net/http/client.fb, line 93

    • Public ReadOnly Field Bytes: UInt8[] field #

      Its bytes.

    • Public ReadOnly Field ContentType: String? field #

      Its Content-Type, or Null to send none.

    • @PanicsAtCaller Public New(bytes: UInt8[], contentType: String? = "application/octet-stream") constructor #

      A Body of bytes, which are what contentType says.

    • @PanicsAtCaller Public Static Method Text(text: String, contentType: String = "text/plain; charset=utf-8"): Body static method #

      text's UTF-8, as plain text unless contentType says another kind.

    • Public Static Method Json(json: String): Body static method #

      JSON's text, as application/json.

    • Public Static Method Form(fields: Map<String, String>): Body static method #

      A form's fields, in their order, as application/x-www-form-urlencoded: each name and value with each byte but the letters, digits, '-', '.', '_', and '~' as %XX, which servers read as they read a browser's '+' for a space, each pair as name=value, and '&' between them.

    Report an issue with this page or with FutureBlitz on GitHub.