Last active
August 29, 2015 14:05
-
-
Save oubiwann/bb61d8c81cce1a1bc27a to your computer and use it in GitHub Desktop.
Comparison of Python (Bottle), Clojure (Compojure), and Erlang/LFE (lfest) REST Routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from example.bottle.bttl import Bottle | |
app = Bottle() | |
@app.get('/') | |
def index(): | |
return "Hello, World!" | |
@app.get('/orders') | |
def get_orders(): | |
return "<h1>All Current Orders:</h1>" | |
@app.post('/order') | |
def post_order(): | |
return "<h1>Order placed.</h1>" | |
@app.get('/order/<id>') | |
def get_order(id): | |
return "<h2>Order " + id + " is not ready.</h2>" | |
@app.put('/order/<id>') | |
def put_order(id): | |
return "<h2>Received update for Order " + id + ".</h2>" | |
@app.delete('/order/<id>') | |
def delete_order(id): | |
return "<h2>All done with Order " + id + "; removed.</h2>" | |
@app.options('/order/<id>') | |
def options_order(id): | |
return "<h2>That order is allowed to...</h2>" | |
@app.get('/payment/order/<id>') | |
def get_payment_order(id): | |
return "<h2>Payment Status</h2>" | |
@app.put('/payment/order/<id>') | |
def put_payment_order(id): | |
return "<h2>Paid for Order " + id + ".</h2>" | |
@app.options('/payment/order/<id>') | |
def options_payment_order(id): | |
return "<h2>That payment can be ...</h2>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns rest-server.routes | |
(:require [compojure.core :refer :all])) | |
(defroutes main-routes | |
(GET "/orders" [] "<h1>All Current Orders:</h1>") | |
(POST "/order" [] "<h1>Order placed.</h1>") | |
(GET "/order/:id" [id] (str "<h2>Order " id " is not ready.</h2>")) | |
(PUT "/order/:id" [id] (str "<h2>Received update for Order " id "</h2>")) | |
(DELETE "/order/:id" [id] (str "<h2>All done with Order " id "</h2>")) | |
(OPTIONS "/order/:id" [id] (str "<h2>That order is allowed to...</h2>")) | |
(GET "/payment/order/:id" [id] (str "<h2>Payment Status</h2>")) | |
(PUT "/payment/order/:id" [id] (str "<h2>Paid for Order " id "</h2>")) | |
(OPTIONS "/payment/order/:id" [id] "<h2>That payment can be...</h2>")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmodule rest-server-routes | |
(export all)) | |
(include-lib "deps/lfest/include/macros.lfe") | |
(defroutes | |
(GET "/orders" "<h1>All Current Orders:</h1>") | |
(POST "/order" "<h1>Order placed.</h1>") | |
(GET "/order/:id" (lambda (id) (++ "<h2>Order " id " is not ready.</h2>"))) | |
(PUT "/order/:id" (lambda (id) (++ "<h2>Received update for Order " id "</h2>"))) | |
(DELETE "/order/:id" (lambda (id) (++ "<h2>All done with Order " id "</h2>"))) | |
(OPTIONS "/order/:id" (lambda (id) (++ "<h2>That order is allowed to...</h2>"))) | |
(GET "/payment/order/:id" (lambda (id) (++ "<h2>Payment Status</h2>"))) | |
(PUT "/payment/order/:id" (lambda (id) (++ "<h2>Paid for Order " id "</h2>"))) | |
(OPTIONS "/payment/order/:id" "<h2>That payment can be...</h2>")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment