Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elixir Plug Cowboy Example
defmodule RecurlyBot do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
# Define workers and child supervisors to be supervised
children = [
# Starts a worker by calling: RecurlyBot.Worker.start_link(arg1, arg2, arg3)
Plug.Adapters.Cowboy.child_spec(:http, RecurlyBot.Router, [], [port: 4001])
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: RecurlyBot.Supervisor]
Supervisor.start_link(children, opts)
end
end
defmodule RecurlyBot.Router do
use Plug.Router
plug :match
plug :dispatch
def start_link do
Plug.Adapters.Cowboy.http(Plugger.Router, [])
end
get "/" do
conn
|> send_resp(200, "Plug!")
end
defp parse_webhook(conn) do
{:ok, body, conn} = Plug.Conn.read_body(conn)
# return a Plug response here
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.