http

Build Status][gh-actions-badge]][gh-actions]
[![LFE Versions][lfe-badge]][lfe]
[![Erlang Versions][erlang-badge] [ Tags

General purpose data, functions, and utilities for use by LFE HTTP clients, servers, URL-parsers, web frameworks, etc.

Project Logo

Table of Contents

Features

Examples

Basic HTTP Client Requests

Start the required applications:

(inets:start)
(ssl:start)

Simple GET request:

> (http.c:request "https://httpbin.org/get")
#(ok #m(status 200
        headers #m(#"Content-Type" #"application/json" ...)
        body #"..."
        version 1.1))

GET request with custom headers:

> (let* ((req (http.request:new "https://httpbin.org/headers"))
         (req-with-headers (http.request:set-header req #"User-Agent" #"lfe-http/1.0")))
    (http.c:request req-with-headers))
#(ok #m(status 200 ...))

POST request with JSON:

> (let* ((body #"{\"name\":\"LFE\",\"type\":\"language\"}")
         (req (http.request:new #"POST" "https://httpbin.org/post"))
         (req-with-json (http.request:set-json req body)))
    (http.c:request req-with-json))
#(ok #m(status 200 ...))

POST with custom headers and body:

> (let* ((headers (http.header:add (http.header:new)
                                    #"Content-Type"
                                    #"application/x-www-form-urlencoded"))
         (body #"key1=value1&key2=value2"))
    (http.c:request #"POST" "https://httpbin.org/post" body headers))
#(ok #m(status 200 ...))

Working with Headers

Create a new headers map:

> (http.header:new)
#m()

Add headers:

> (let* ((h1 (http.header:new))
         (h2 (http.header:add h1 #"Content-Type" #"application/json"))
         (h3 (http.header:add h2 #"Accept" #"application/json")))
    h3)
#m(#"Content-Type" #"application/json"
   #"Accept" #"application/json")

Convert from a property list:

> (http.header:from-list '(#(#"Content-Type" #"text/plain")
                            #(#"Accept" #"*/*")))
#m(#"Content-Type" #"text/plain"
   #"Accept" #"*/*")

Get header values (case-sensitive):

> (let ((headers (http.header:from-list '(#(#"Content-Type" #"application/json")))))
    (http.header:get headers #"Content-Type"))
#"application/json"

Get header values (case-insensitive):

> (let ((headers (http.header:from-list '(#(#"Content-Type" #"application/json")))))
    (http.header:get headers #"content-type" 'undefined #m(case-insensitive true)))
#"application/json"

Merge headers:

> (let ((h1 (http.header:from-list '(#(#"Accept" #"application/json"))))
        (h2 (http.header:from-list '(#(#"Content-Type" #"text/plain")))))
    (http.header:merge h1 h2))
#m(#"Accept" #"application/json"
   #"Content-Type" #"text/plain")

Installation

Add it to your rebar.config deps:

{deps, [
  ...
  {http, "1.0.0", {pkg, lfe_http}}
]}.

License

Apache License, Version 2.0

Copyright © 2023-2025, Duncan McGreggor oubiwann@gmail.com.