gleam/http

Functions for working with HTTP data structures in Gleam.

This module makes it easy to create and modify Requests and Responses, data types. A general HTTP message type is defined that enables functions to work on both requests and responses.

This module does not implement a HTTP client or HTTP server, but it can be used as a base for them.

Types

A HTTP header is a key-value pair. Header keys should be all lowercase characters.

pub type Header =
  #(String, String)

HTTP standard method as defined by RFC 2616, and PATCH which is defined by RFC 5789.

pub type Method {
  Get
  Post
  Head
  Put
  Delete
  Trace
  Connect
  Options
  Patch
  Other(String)
}

Constructors

  • Get
  • Post
  • Head
  • Put
  • Delete
  • Trace
  • Connect
  • Options
  • Patch
  • Other(String)

    Non-standard but valid HTTP methods.

The two URI schemes for HTTP

pub type Scheme {
  Http
  Https
}

Constructors

  • Http
  • Https

Functions

pub fn method_from_dynamic(value: Dynamic) -> Result(
  Method,
  List(DecodeError),
)
pub fn method_to_string(method: Method) -> String
pub fn parse_method(s: String) -> Result(Method, Nil)
pub fn scheme_from_string(scheme: String) -> Result(Scheme, Nil)

Parse a HTTP scheme from a string

Examples

> scheme_to_string("http")
Ok(Http)

> scheme_to_string("ftp")
Error(Nil)
pub fn scheme_to_string(scheme: Scheme) -> String

Convert a scheme into a string.

Examples

> scheme_to_string(Http)
"http"

> scheme_to_string(Https)
"https"