Skip to content

Instantly share code, notes, and snippets.

@poteto
Last active February 8, 2024 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poteto/8eecc8b9e84f4e0c804864c4a71f60e9 to your computer and use it in GitHub Desktop.
Save poteto/8eecc8b9e84f4e0c804864c4a71f60e9 to your computer and use it in GitHub Desktop.
defmodule MyApp.Terraformers.LegacyApi do
alias MyApp.Clients.LegacyApi
use Plug.Router
plug :match
plug :dispatch
get _ do
%{method: "GET", request_path: request_path, params: params, req_headers: req_headers} = conn
res = LegacyApi.get!(request_path, req_headers, [params: Map.to_list(params)])
send_response({:ok, conn, res})
end
def send_response({:ok, conn, %{headers: headers, status_code: status_code, body: body}}) do
conn = %{conn | resp_headers: headers}
send_resp(conn, status_code, body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment