/minimal_http_server

Minimal HTTP server for testing and debugging purposes

Primary LanguageElixir

Minimal HTTP server

This is a minimal HTTP server using

  • Elixir
  • Plug
  • Bandit

Used for testing and debugging.

Supports HTTP/HTTPS and WebSockets.

Usage

  • replace self-signed certificates in certs/ if HTTPS is needed;
  • update server.exs to match your needs, drop the things you don't need;
  • run the server
elixir server.exs

Accessing

HTTPS with curl

curl --resolve server:4001:127.0.0.1 --cacert certs/ca.crt 'https://server:4001/test'

HTTP with curl

curl 'http://127.0.0.1:4000/test'

WebSocket with browser & console

sock = new WebSocket("ws://localhost:4000/websocket");
sock.addEventListener("message", console.log);
sock.addEventListener("open", console.log)
...
sock.send("ping")

WebSocket with wscat

npx wscat -c ws://127.0.0.1:4000/websocket
Connected (press CTRL+C to quit)
> ping
< pong