Skip to content

Instantly share code, notes, and snippets.

View ekhall's full-sized avatar

EK Hall ekhall

  • Personal
  • New York, USA
View GitHub Profile

How to build a JSON API with Elixir & Phoenix

Welcome! In this guide we'll go step by step to build an API with Elixir and the Phoenix Framework.

Note, i wrote this around 2017/18 so things might have changed. Also it's incomplete. Hopefully still useful. Yadayada.

Here's the plan:

  • Install Elixir
  • Create a new Phoenix project
@ekhall
ekhall / Main.hs
Created January 18, 2021 15:36
Haskel1-escrow
{-# LANGUAGE OverloadedStrings #-}
module Escrow where
import Language.Marlowe
main :: IO ()
main = print . pretty $ contract
{- What does the vanilla contract look like?
@ekhall
ekhall / blockly.xml
Created January 18, 2021 15:32
Marlowe-Demo-1-complete
<xml xmlns="https://developers.google.com/blockly/xml"><block type="BaseContractType" id="root_contract" deletable="false" x="10" y="50"><statement name="BaseContractType"><block type="WhenContractType" id="y!W4x5;|#kYuS~ZPA*V)"><field name="timeout">0</field><statement name="case"><block type="DepositActionType" id="}Ru~BD,pT-EDsLhX}%Qr"><value name="from_party"><block type="RolePartyType" id="cG9yhl,bNE:jSUA09O=$"><field name="role">Client</field></block></value><value name="value"><block type="ConstantValueType" id="ximMy:=YelA).DioyDAY"><field name="constant">50</field></block></value><value name="token"><block type="AdaTokenType" id="2ooyW/@FEyoG#U7/%9q]"/></value><value name="party"><block type="RolePartyType" id="G+D=G883]{``:GbU3H;="><field name="role">Client</field></block></value><statement name="contract"><block type="WhenContractType" id="K:39[mUJf7HXGa!zzJrP"><field name="timeout">7</field><statement name="case"><block type="ChoiceActionType" id=",k/kgDiKOR6TG#=o749|"><field name="choice_name">na
@ekhall
ekhall / blockly.xml
Last active January 18, 2021 15:32
Marlowe-Demo-1
<xml xmlns="https://developers.google.com/blockly/xml"><block type="BaseContractType" id="root_contract" deletable="false" x="10" y="50"><statement name="BaseContractType"><block type="WhenContractType" id="y!W4x5;|#kYuS~ZPA*V)"><field name="timeout">0</field><statement name="case"><block type="DepositActionType" id="}Ru~BD,pT-EDsLhX}%Qr"><value name="from_party"><block type="RolePartyType" id="cG9yhl,bNE:jSUA09O=$"><field name="role">Client</field></block></value><value name="value"><block type="ConstantValueType" id="ximMy:=YelA).DioyDAY"><field name="constant">50</field></block></value><value name="token"><block type="AdaTokenType" id="2ooyW/@FEyoG#U7/%9q]"/></value><value name="party"><block type="RolePartyType" id="G+D=G883]{``:GbU3H;="><field name="role">Client</field></block></value><statement name="contract"><block type="WhenContractType" id="K:39[mUJf7HXGa!zzJrP"><field name="timeout">7</field><statement name="case"><block type="ChoiceActionType" id=",k/kgDiKOR6TG#=o749|"><field name="choice_name">na
(ns giggin.api
(:require [ajax.core :refer [GET]]
[giggin.state :as state]
[clojure.walk :as walk]))
(defn handler
"Resets the state/gigs atom (app state) to the response of the following data
transformation. A GET request is made to the URL below in fetch-gigs. The
keywords? option below turns all JSON key strings into symbols (`key`: `string`
to :key `string`). The `response` is then passed to the series of function calls."
(defproject archetyp-website "0.1.0-SNAPSHOT"
:description "Archetyp Mobility Website in Reagent/React"
:url "http://archetyp.io"
:license {:name "Copyright 2017 Archetyp Mobility LLC"
:url "http://archetyp.io"}
:dependencies [[org.clojure/clojure "1.8.0"]
[ring-server "0.4.0"]
[reagent "0.6.0"]
[reagent-utils "0.2.0"]
~/Dropbox/Code/React/iSPIWebsite/ git push heroku [17:36:39]
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 600 bytes | 0 bytes/s, done.
Total 6 (delta 4), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected

Keybase proof

I hereby claim:

  • I am ekhall on github.
  • I am eugekev (https://keybase.io/eugekev) on keybase.
  • I have a public key whose fingerprint is CF3C CF7A D21D DFD0 DC64 A517 0F9D 881D 59D3 8232

To claim this, I am signing this object:

(ns aurora.models.lab
(:require [clojure.java.jdbc :as sql]
[twilio.core :as twilio]
[clojurewerkz.machine-head.client :as mh]))
(defn send-mqtt [message & args]
(let [id (mh/generate-id)
conn (mh/connect mqtt-url id)]
(mh/subscribe conn ["gossamer"] (fn [^String topic _ ^bytes payload]
(println (String. payload "UTF-8"))))
@ekhall
ekhall / f
Created December 11, 2015 21:24
web: java $JVM_OPTS -cp target/queuing-standalone.jar clojure.main -m queuing.web