Created
November 30, 2016 01:50
-
-
Save bhelx/062ae2d78ab4768ab527d3db74f1869e to your computer and use it in GitHub Desktop.
Elixir Plug Cowboy Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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