Skip to content

Instantly share code, notes, and snippets.

@laser
laser / services.rb
Created April 14, 2014 17:48
13: Rails client speaking HTTP
# config/initializers/services.rb
require 'barrister-rails'
require 'barrister-redis'
class Services
# ...
def self.proxy_services
@laser
laser / routes.txt
Created April 21, 2014 22:05
route table
+---------------------------------------------------------------+
| PATH | VERB | NOTE |
+------------+--------+-----------------------------------------+
| /todos | GET | Retrieve a list of todos |
| /todos | POST | Create a new todo |
| /todos/:id | PUT | Replace the todo with the provided todo |
| /todos/:id | DELETE | Delete the todo |
+------------+--------+-----------------------------------------+
@laser
laser / api.txt
Created April 21, 2014 22:05
api markdown
# TODO_API.README
## Retrieve a list of todos
### Example request:
GET http://api.example.com/v1/todos
Content-Type: application/json;
### Example response
@laser
laser / express_rest.js
Created April 21, 2014 22:15
express rest server impl
// Node.js Server: RMM Level Two
var express = require('express')
, http = require('http')
, path = require('path')
, store = require("./store").store;
var app = express();
app.use(express.bodyParser());
@laser
laser / jquery_rest_client.js
Last active August 29, 2015 14:00
jquery basic rest api client
// REST API Client Definition
var apiClient = (function() {
var ajax = function(url, type, callback, data) {
var config = {
dataType: 'json',
error: function(xhr, status, text) {
return callback({
xhr: xhr,
status: status,
@laser
laser / todo_manager.idl
Created April 21, 2014 22:19
todo manager IDL
// todo_manager.idl
struct TodoProperties {
title string
completed bool
}
struct Todo extends TodoProperties {
id int [optional]
}
@laser
laser / server_rpc.js
Created April 21, 2014 22:22
Barrister RPC + Express
// Server: Barrister RPC + Express
var express = require('express')
, fs = require('fs')
, http = require('http')
, path = require('path')
, barrister = require('barrister')
, store = require("./store").store
, idl = JSON.parse(fs.readFileSync("./todo_manager.json").toString());
@laser
laser / jquery_rpc_client.js
Created April 21, 2014 22:24
jquery RPC client
// Barrister Client Initialization
function initApp(callback) {
var client = Barrister.httpClient({
'endpoint': '/todos',
'interfaces': ['TodoManager']
});
client.loadContract(function() {
var proxy = client.proxy('TodoManager');
@laser
laser / documeting_error_code.idl
Created April 21, 2014 22:29
Barrister IDL w/error code
interface TodoManager {
// returns all Todos
readTodos() []Todo
// creates new Todo and returns it with an id
createTodo(todo TodoProperties) Todo
// updates Todo and returns it
updateTodo(todo Todo) Todo
@laser
laser / todo_manager.js
Created April 21, 2014 22:31
TodoManager raising an error
// Changing TodoManager Implementation
server.addHandler('TodoManager', {
'readTodos': function(callback) {
callback(null, store.getAll());
},
'createTodo': function(props, callback) {
callback(null, store.save(props));
},
'updateTodo': function(id, props, callback) {