{"id":15540432,"url":"https://github.com/poteto/terraform","last_synced_at":"2025-05-16T13:06:18.287Z","repository":{"id":54299595,"uuid":"65160389","full_name":"poteto/terraform","owner":"poteto","description":"A simple plug for incrementally transforming an API into Phoenix. Check out the blog post:","archived":false,"fork":false,"pushed_at":"2021-02-25T18:19:19.000Z","size":20,"stargazers_count":418,"open_issues_count":2,"forks_count":13,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-03T09:08:26.035Z","etag":null,"topics":["elixir","phoenix","plug","reverse-proxy"],"latest_commit_sha":null,"homepage":"https://www.no.lol/2016-08-12-rise-from-the-ashes-incremental-apis-with-phoenix/","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poteto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-08T00:20:50.000Z","updated_at":"2025-03-31T00:39:33.000Z","dependencies_parsed_at":"2022-08-13T11:20:46.202Z","dependency_job_id":null,"html_url":"https://github.com/poteto/terraform","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fterraform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fterraform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fterraform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fterraform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poteto","download_url":"https://codeload.github.com/poteto/terraform/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248531514,"owners_count":21119777,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","phoenix","plug","reverse-proxy"],"created_at":"2024-10-02T12:13:44.733Z","updated_at":"2025-04-12T07:23:27.971Z","avatar_url":"https://github.com/poteto.png","language":"Elixir","readme":"# terraform [![Hex](https://img.shields.io/hexpm/v/terraform.svg)](https://hex.pm/packages/terraform) [![Build Status](https://travis-ci.com/poteto/terraform.svg?branch=master)](https://travis-ci.com/poteto/terraform) ![Phoenix compatibility](https://img.shields.io/badge/phoenix%20compat-%3E%3D%201.2.0%20and%20%3C%3D%201.5.x-blue)\n\nTerraform is a simple `Plug` designed to work with Phoenix. Terraform allows you to incrementally transform a HTTP API into one powered by Phoenix - one endpoint at a time.\n\nView the [demo Phoenix app](https://github.com/poteto/reverse_proxy).\n\n## Phoenix Compatibility\n\nThis package is explicitly tested against the following Phoenix versions:\n\n| Phoenix version  | Compatibility |\n| ------------- | ------------- |\n| ~\u003e 1.2.0  | ✅  |\n| ~\u003e 1.3.0  | ✅  |\n| ~\u003e 1.4.0  | ✅  |\n| ~\u003e 1.5.0  | ✅  |\n\n## Installation\n\nAdd `terraform` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:terraform, \"~\u003e 1.0.1\"}]\nend\n```\n\n## Usage\n\nFirst, add it to `web/router.ex`:\n\n```elixir\ndefmodule MyApp.Router do\n  use Terraform, terraformer: MyApp.Terraformers.Foo\n\n  # ...\nend\n```\n\nThen, define a new `Terraformer`, which uses `Plug.Router`. Any request that goes to a route that isn't defined on your Phoenix app will hit this plug, and you can then handle it using a familiar DSL. Refer to [hexdocs](https://hexdocs.pm/plug/Plug.Router.html) for documentation about `Plug.Router`.\n\nHere's a basic example:\n\n```elixir\ndefmodule MyApp.Terraformers.Foo do\n  alias MyApp.Clients.Foo # example client made with HTTPoison\n  use Plug.Router\n\n  plug :match\n  plug :dispatch\n\n  # match specific path\n  get \"/v1/hello-world\", do: send_resp(conn, 200, \"Hello world\")\n\n  # match all `get`s\n  get _ do\n    %{method: \"GET\", request_path: request_path, params: params, req_headers: req_headers} = conn\n    res = Foo.get!(request_path, req_headers, [params: Map.to_list(params)])\n    send_response({:ok, conn, res})\n  end\n\n  def send_response({:ok, conn, %{headers: headers, status_code: status_code, body: body}}) do\n    conn = %{conn | resp_headers: headers}\n    send_resp(conn, status_code, body)\n  end\nend\n```\n\n### Reading the request body\n\n`Plug` has an elegant solution to this problem using [`Plug.Conn.read_body`](https://hexdocs.pm/plug/Plug.Conn.html#read_body/2). Refer to this [comment](https://github.com/phoenixframework/phoenix/issues/459#issuecomment-440820663) for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoteto%2Fterraform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoteto%2Fterraform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoteto%2Fterraform/lists"}