• Stars
    star
    414
  • Rank 104,550 (Top 3 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

hiring-without-whiteboards

โญ๏ธ Companies that don't have a broken hiring process
JavaScript
44,261
star
2

elixirconf-2016

ElixirConf 2016 summary
569
star
3

rustconf-2020

An aggregation of links that summarize RustConf 2020. Pull requests welcome!
356
star
4

emberconf-2016

A collection of links that cover what happened during EmberConf 2016
268
star
5

emberconf-2015

A collection of links that cover what happened during EmberConf 2015
244
star
6

ember-crumbly

Declarative breadcrumb navigation for Ember apps
JavaScript
167
star
7

component-best-practices

Code samples for Component Best Practices talk
HTML
129
star
8

elixirconf-2017

ElixirConf 2017 summary
109
star
9

emberconf-2017

A collection of links that summarize EmberConf 2017
JavaScript
101
star
10

ember-macaroni

Keep your app code DRY and copypasta free with computed property macaronis (macros)
JavaScript
99
star
11

no.lol

๐Ÿฉ Lauren's personal blog
TypeScript
62
star
12

ember-hypersearch

Hyperspeed real-time search with caching
JavaScript
55
star
13

reverse_proxy

Terraform demo - incrementally replace your API with Phoenix
JavaScript
51
star
14

ember-lazy-video

Lazy load videos in an Ember app
JavaScript
46
star
15

ember-workshop

This is a workshop designed for intermediate developers who have worked on at least one large Ember app. The goal is to teach functional programming basics and to be able to use these ideas in your app.
45
star
16

monkers

Bytecode compiler and VM for the Monkeylang language, written in Rust
Rust
44
star
17

peedy

PDF watermarking microservice written in Elixir. For educational purposes only - not meant for production
Elixir
36
star
18

ember-deep-set

Deeply set values on an Ember Object or POJO
JavaScript
33
star
19

boba-js

Toy programming language. Now being reimplemented in Rust: https://github.com/poteto/monkers
TypeScript
30
star
20

advent-of-code-2018

Learning rust from scratch
Rust
21
star
21

ember-test-component

Test helper for using dependency injected components
JavaScript
21
star
22

hww-api

Small API to process additions to https://github.com/poteto/hiring-without-whiteboards and push them into an Airtable
JavaScript
18
star
23

ember-pipeline

Railway oriented programming in Ember
JavaScript
18
star
24

ember-toggle-helper

Dead simple toggle helper
JavaScript
16
star
25

poteto

13
star
26

ember-api-feature-flags

API based, read-only feature flags for Ember
JavaScript
12
star
27

validated-proxy

Typesafe, validated ES2015 proxies
TypeScript
11
star
28

elixir-workshop-pragdave

Elixir
6
star
29

vscode-tinacious-contrast

A high contrast version of Tinacious Design Syntax, a theme for VS Code
5
star
30

bitburner-scripts

Personal scripts for bitburner
JavaScript
5
star
31

rustic

Rust
3
star
32

ember-ja-query

JSON API response query interface
JavaScript
3
star
33

ember-gsg-reference

Getting started with Ember.js
CSS
3
star
34

flushed

flushed-app
JavaScript
2
star
35

orion_takehome

JavaScript
2
star
36

number1.pizza

TypeScript
2
star
37

-_-

๐Ÿ’ฉ
2
star
38

elixir-portal-test

Elixir
1
star
39

react-test

JavaScript
1
star
40

birthday-puzzle

Stupid little puzzle for my bf's birthday dinner location
JavaScript
1
star
41

ember-in-viewport-demo

Demo app for ember-in-viewport
CSS
1
star
42

remark-lint-hiring-without-whiteboards-links

JavaScript
1
star
43

e4e-2015

Notes from the engineers4engineers conference
1
star
44

styleguides

Styleguides for DockYard
1
star
45

ember-crumbly-demo

demo app for ember-crumbly
JavaScript
1
star
46

steamcircle

Expand your gaming circle
JavaScript
1
star
47

ember-redux-experiment

JavaScript
1
star
48

deadcrabs

JavaScript
1
star
49

ember-gsg

1
star