Skip to content

Instantly share code, notes, and snippets.

@bhelx
Created November 30, 2016 01:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhelx/062ae2d78ab4768ab527d3db74f1869e to your computer and use it in GitHub Desktop.
Save bhelx/062ae2d78ab4768ab527d3db74f1869e to your computer and use it in GitHub Desktop.
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