Skip to content

Instantly share code, notes, and snippets.

@Enforcer
Created March 22, 2019 16:09
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 Enforcer/24b928471ff79d6a2aac6bbbdc9b7418 to your computer and use it in GitHub Desktop.
Save Enforcer/24b928471ff79d6a2aac6bbbdc9b7418 to your computer and use it in GitHub Desktop.
defmodule Wallets.Router do
use Plug.Router
plug(:match)
plug(:fetch_query_params)
plug(:dispatch)
get "/balance" do
send_resp(conn, 200, "Not implemented")
end
# Example: curl -X POST 'http://localhost:8080/credit?owner_id=1&currency_id=3&amount=100'
post "/credit" do
IO.inspect(conn.query_params)
owner_id = conn.query_params["owner_id"]
currency_id = conn.query_params["currency_id"]
amount = conn.query_params["amount"]
send_resp(conn, 200, "Credited #{amount} of #{currency_id} to #{owner_id}")
end
post("/debit", do: send_resp(conn, 200, "Not implemented"))
match(_, do: send_resp(conn, 404, "Not Found"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment