Skip to content

gleam-lang/httpd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpd

Bindings to Erlang's built in HTTP server, httpd.

Package Version Hex Docs

gleam add gleam_httpd@1
import gleam/httpd
import gleam/http/request.{type Request}
import gleam/http/response.{type Response}
import gleam/bytes_tree.{type BytesTree}

// Write your request handler, a function that takes a request and 
// returns a response.
pub fn handle_request(_request: Request(BitArray)) -> Response(BytesTree) {
  let body = bytes_tree.from_string("Welcome!")
  response.new(200)
  |> response.set_body(body)
}

// Start a httpd server using your request handler.
pub fn start() -> _ {
  httpd.new(handle_request)
  |> httpd.port(3000)
  |> httpd.start
}

Further documentation can be found at https://gleam-httpd.hexdocs.pm/.

When should you use this?

httpd is a HTTP1.1 server that is included with the standard Erlang distribution. If you don't need web sockets, server sent events, request body streaming, or higher HTTP versions then httpd could be a great choice!

If you need more than httpd offers then there are more sophisticated BEAM HTTP servers that you can add as a dependency and use, such as Ewe and Mist.

About

🛰️ Serve HTTP requests with httpd

Resources

Code of conduct

Security policy

Stars

8 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors