Skip to content

Instantly share code, notes, and snippets.

@avinayak
Last active May 15, 2022 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avinayak/e23ace8fbcc451ccb1af1cfcc56fa9cd to your computer and use it in GitHub Desktop.
Save avinayak/e23ace8fbcc451ccb1af1cfcc56fa9cd to your computer and use it in GitHub Desktop.
Simplest plug based http sever
# run with $ elixir --no-halt hello.exs
Mix.install([{:plug_cowboy, "~> 2.0"}])
defmodule HWPlug.Plug do
import Plug.Conn
def init(options), do: options
def call(conn, _opts) do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "Hello World!\n")
end
end
Plug.Adapters.Cowboy.http(HWPlug.Plug, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment