Last active
February 8, 2024 14:22
-
-
Save poteto/8eecc8b9e84f4e0c804864c4a71f60e9 to your computer and use it in GitHub Desktop.
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 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