Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Kelly mikekelly

View GitHub Profile
View gist:232891
dir structure:
/lib/
/tmp/
/views/
/public/
/config.ru
/blog.rb
--
View nodular_ponderings.js
/*
I want to be able to build a DSL for node.js so that I can define app routes for an HTTP interface like this:
*/
{
"/blog" : {
GET: function(request) {
// List blog posts
},
View gist:369466
#(entry point)
> GET /
< 200 OK
< Link: </lists/some-list>; rel="http://example.com/rels/list",
< </foobars/another-list>; rel="http://example.com/rels/list"
< {...}
<html>
<head>
View hal-list.xml
(GET /list)
<link rel="self" href="/list">
<link rel="description" href="/list/description" />
<link rel="search" href="/list/search/{search_term}" />
<created_at>2010-01-16</created_at>
<updated_at>2010-02-21</updated_at>
<summary>An example list</summary>
<link rel="owner" href="/people/mike">
<name>Mike</name>
View Gemfile
# Critical default settings:
disable_system_gems
disable_rubygems
bundle_path '.gems/bundler_gems'
# List gems to bundle here:
gem 'rails_dm_datastore'
gem 'rails', "2.3.5"
# Needed for Devise-Plugin
View jotting ideas.js
// (/app/resources/useraccount.js)
Resource({
respond_to: ["html", "xml", "json"],
http: {
GET: function() {
user = User.find(params.user);
respond_with(user);
},
PUT: function() {
View list.xml
<resource rel="self" href="/list">
<resource rel="description" href="/list/description" />
<resource rel="search" href="/list/search/{search_term}" />
<created_at>2010-01-16</created_at>
<updated_at>2010-02-21</updated_at>
<summary>An example list</summary>
<resource rel="owner" href="/people/mike">
<name>Mike</name>
<age>36</age>
</resource>
View hal-example.xml
<resource href="/orders">
<link rel="next" href="/orders?page=2" />
<link rel="search" href="/orders?id={order_id}" />
<resource rel="order" href="/orders/123">
<link rel="customer" href="/customer/bob" title="Bob Jones <bob@jones.com>" />
<resource rel="basket" href="/orders/123/basket">
<item>
<sku>ABC123</sku>
<quantity>2</quantity>
<price>9.50</price>
View halv2.json
{
"_links" : {
"search" : { "href" : "/todo-list/search;{searchterm}" },
"description" : { "href" : "/todo-list/description" }
},
"_embedded" : {
"owner" : {
"_links" : {
"self" : { "href" : "http://range14sux.com/mike"},
"friend" : { "href": "http://mamund.com/" }
View http.html
<html>
<head>
<title>Example of HTTP microformat</title>
</head>
<body>
<div class="http">
<div class="request">
<div class="line">
<span class="method">POST</span> <span class="resource">/foo/bar</span> <span class="http-version">HTTP/1.1</span>
</div>