All Projects → poteto → Terraform

poteto / Terraform

Licence: mit
A simple plug for incrementally transforming an API into Phoenix. Check out the blog post:

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Terraform

Liberator
An Elixir library for building RESTful applications.
Stars: ✭ 28 (-92.61%)
Mutual labels:  phoenix, plug
Absinthe plug
Plug support for Absinthe, the GraphQL toolkit for Elixir
Stars: ✭ 209 (-44.85%)
Mutual labels:  phoenix, plug
Authex
Authex is an opinionated JWT authentication and authorization library for Elixir.
Stars: ✭ 73 (-80.74%)
Mutual labels:  phoenix, plug
Reverse proxy plug
🔛 an Elixir reverse proxy Plug with HTTP/2, chunked transfer and path proxying support
Stars: ✭ 112 (-70.45%)
Mutual labels:  plug, reverse-proxy
guardian trackable
A Guardian hook to track user sign ins.
Stars: ✭ 25 (-93.4%)
Mutual labels:  phoenix, plug
Logster
Easily parsable single line, plain text and JSON logger for Plug and Phoenix applications
Stars: ✭ 171 (-54.88%)
Mutual labels:  phoenix, plug
Appsignal Elixir
🟪 AppSignal for Elixir package
Stars: ✭ 176 (-53.56%)
Mutual labels:  phoenix, plug
alternate
Plug and Phoenix helpers to localize your web app via the URL
Stars: ✭ 26 (-93.14%)
Mutual labels:  phoenix, plug
plug rest
REST behaviour and Plug router for hypermedia web applications in Elixir
Stars: ✭ 52 (-86.28%)
Mutual labels:  phoenix, plug
phoenix-client-ssl
Set of Plugs / Lib to help with SSL Client Auth.
Stars: ✭ 18 (-95.25%)
Mutual labels:  phoenix, plug
Guardian
Elixir Authentication
Stars: ✭ 3,150 (+731.13%)
Mutual labels:  phoenix, plug
accent
Dynamically convert the case of your JSON API keys
Stars: ✭ 27 (-92.88%)
Mutual labels:  phoenix, plug
plug rails cookie session store
Rails compatible Plug session store
Stars: ✭ 93 (-75.46%)
Mutual labels:  phoenix, plug
Phoenix slime
Phoenix Template Engine for Slime
Stars: ✭ 286 (-24.54%)
Mutual labels:  phoenix
Modlishka
Modlishka. Reverse Proxy.
Stars: ✭ 3,634 (+858.84%)
Mutual labels:  reverse-proxy
Cercle
Cercle is a CRM+Project Manager for your organization - Phoenix Framework & Vuejs
Stars: ✭ 284 (-25.07%)
Mutual labels:  phoenix
Turbo
A lightweight microservice tool, turn your grpc|thrift APIs into HTTP APIs!
Stars: ✭ 275 (-27.44%)
Mutual labels:  reverse-proxy
Hammer
An Elixir rate-limiter with pluggable backends
Stars: ✭ 366 (-3.43%)
Mutual labels:  phoenix
Loopa News
Realtime social news app developed from scratch with Elixir, Phoenix, Vue and Vuex
Stars: ✭ 308 (-18.73%)
Mutual labels:  phoenix
Open Proxy
一键部署被墙网站反向代理; 免翻墙访问被禁网站
Stars: ✭ 274 (-27.7%)
Mutual labels:  reverse-proxy

terraform Hex Build Status Phoenix compatibility

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].