Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / main.rb
Last active August 29, 2015 13:59
12: MailService Sinatra container
# services/mail_service/main.rb
require 'barrister-sinatra'
opts = {
mount_path: '/api',
port: ENV['PORT']
}
Barrister::SinatraContainer.new('./interface.json', MailService.new, opts).start
@laser
laser / Procfile
Created April 14, 2014 17:44
11: Procfile for Redis
# Procfile
web: bundle exec rails s -p $PORT
mail_service: sh -c 'cd services/mail_service; ./main.rb'
user_service: sh -c 'cd services/user_service; ./main.rb'
@laser
laser / services.rb
Created April 14, 2014 17:43
10: Rails client using Redis
# config/initializers/services.rb
require 'barrister-rails'
require 'barrister-redis'
class Services
# ...
def self.proxy_services
@laser
laser / main.rb
Created April 14, 2014 17:42
09: UserService Redis container
# services/user_service/main.rb
require 'activerecord'
require 'barrister-redis'
# establish a connection to the database
db_config = YAML.load(ERB.new(File.read('../../config/database.yml')).result)
ActiveRecord::Base.establish_connection db_config[ENV['RACK_ENV'] || 'development']
# create our MailService proxy
@laser
laser / main.rb
Last active August 29, 2015 13:59
08: MailService RedisContainer
# services/mail_service/main.rb
require 'barrister-redis'
opts = {
database_url: ENV['OPENREDIS_URL'],
list_name: 'mail_service'
}
Barrister::RedisContainer.new('./interface.json', MailService.new, opts).start