poteto/terraform
소개
API를 단계적으로 Phoenix로 변환하는 간단한 플러그인입니다. 블로그 글을 확인하세요:
시스템 및 인프라측정된 스타 증가
- in 24h
- +1
- in 7 days
- +1
- in 15 days
- +2
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalterraform

Terraform 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.
View the demo Phoenix app.
Phoenix Compatibility
This package is explicitly tested against the following Phoenix versions:
| Phoenix version | Compatibility |
|---|---|
| ~> 1.2.0 | ✅ |
| ~> 1.3.0 | ✅ |
| ~> 1.4.0 | ✅ |
| ~> 1.5.0 | ✅ |
Installation
Add terraform to your list of dependencies in mix.exs:
def deps do
[{:terraform, "~> 1.0.1"}]
end
Usage
First, add it to web/router.ex:
defmodule MyApp.Router do
use Terraform, terraformer: MyApp.Terraformers.Foo
# ...
end
Then, 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 for documentation about Plug.Router.
Here's a basic example:
defmodule MyApp.Terraformers.Foo do
alias MyApp.Clients.Foo # example client made with HTTPoison
use Plug.Router
plug :match
plug :dispatch
# match specific path
get "/v1/hello-world", do: send_resp(conn, 200, "Hello world")
# match all `get`s
get _ do
%{method: "GET", request_path: request_path, params: params, req_headers: req_headers} = conn
res = Foo.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
Reading the request body
Plug has an elegant solution to this problem using Plug.Conn.read_body. Refer to this comment for details.
관련 프로젝트 살펴보기
불러오는 중…