This file contains hidden or 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
# config/initializers/services.rb | |
require 'barrister-rails' | |
require 'barrister-redis' | |
class Services | |
# ... | |
def self.proxy_services |
This file contains hidden or 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
+---------------------------------------------------------------+ | |
| 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 | | |
+------------+--------+-----------------------------------------+ |
This file contains hidden or 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
# TODO_API.README | |
## Retrieve a list of todos | |
### Example request: | |
GET http://api.example.com/v1/todos | |
Content-Type: application/json; | |
### Example response |
This file contains hidden or 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
// 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()); |
This file contains hidden or 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
// 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, |
This file contains hidden or 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
// todo_manager.idl | |
struct TodoProperties { | |
title string | |
completed bool | |
} | |
struct Todo extends TodoProperties { | |
id int [optional] | |
} |
This file contains hidden or 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
// 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()); |
This file contains hidden or 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
// Barrister Client Initialization | |
function initApp(callback) { | |
var client = Barrister.httpClient({ | |
'endpoint': '/todos', | |
'interfaces': ['TodoManager'] | |
}); | |
client.loadContract(function() { | |
var proxy = client.proxy('TodoManager'); |
This file contains hidden or 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
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 |
This file contains hidden or 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
// 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) { |