Skip to content

Instantly share code, notes, and snippets.

@laser
laser / json-middleware.clj
Last active August 29, 2015 14:11
Adding JSON middleware
(ns pipeline.core
(:require [compojure.core :refer [POST defroutes]]
[ring.middleware.json :refer [wrap-json-response wrap-json-body]]
[ring.util.response :refer [response]])
(:gen-class))
(defn post-notes-handler
[req-body]
(response req-body))
@laser
laser / curl.txt
Last active August 29, 2015 14:11
cURL to web service
curl \
-H "Content-Type: application/json" \
-d '{"text":"xyz"}' \
http://localhost:3000/notes
RESPONSE: {"text":"xyz"}
@laser
laser / scaffolding.clj
Last active August 29, 2015 14:11
Web app scaffolding
(ns pipeline.core
(:require [compojure.core :refer [POST defroutes]]
[ring.util.response :refer [response]]))
(defn post-notes-handler
[req-body]
(response req-body))
(defroutes app
(POST "/notes" {req-body :body} (post-notes-handler req-body)))
@laser
laser / echo-input-to-output.txt
Last active August 29, 2015 14:11
Echo input to output
application input: HttpInput (HTTP request body)
|
|
+--> post-notes-handler: HttpInput (returns what it's passed)
|
|
+--> response: Hash Map (a shell HTTP response)
|
|
+--> application output
@laser
laser / add-json-wrappers.txt
Last active August 29, 2015 14:11
Add Ring JSON middleware
application input: HttpInput (HTTP request body)
|
|
+--> wrap-json-body: Hash Map (deserialized from JSON)
|
|
+--> post-notes-handler: Hash Map (returns what it's been passed)
|
|
+--> response: Hash Map (a shell HTTP response)
@laser
laser / adding-validation.txt
Last active August 29, 2015 14:11
Add validation
application input: HttpInput (HTTP request body)
|
|
+--> wrap-json-body: Hash Map
|
|
+--> post-notes-handler: Hash Map
|
|
+--> validate-note: [Hash Map, Error String] (present? correct length?)
@laser
laser / connect-to-database.txt
Last active August 29, 2015 14:11
Connecting to a database
application input: HttpInput (HTTP request body)
|
|
+--> wrap-json-body: Hash Map
|
|
+--> post-notes-handler: Hash Map
|
|
+--> validate-note: [Hash Map, Error String]
@laser
laser / sourceme.sh
Created December 9, 2014 21:43
source me
export DATABASE_URL="postgres://psql@localhost:5432/soundselect"
export BONSAI_URL=http://localhost:9200
export TZ='UTC'
export RBSS_HEAPDUMP_INTERVAL=5
@laser
laser / example.md
Last active August 29, 2015 14:09
API Concepts

Users Collection Resource

Get some users

Example Request (collection resource)
GET https://example.com/users?offset=0&limit=10
@laser
laser / drop_recreate.sh
Created November 6, 2014 18:15
drop / recreate test database script
RAILS_ENV=test bundle exec rake db:drop db:create
echo '\x \\ DROP EXTENSION postgis CASCADE;' | psql zzz_test
echo '\x \\ CREATE EXTENSION postgis;' | psql zzz_test
RAILS_ENV=test rake db:schema:load
bundle exec rspec spec/queries/listings_query_spec.rb:131
git stash