linen

Linen (line-in) maps API's to bindable objects, and collections. At classdojo, we use linen to abstract our API from front-end, so we don't necessarily depend on any sort of API while developing new components. This allows us to rapidly build prototypes which can be wired up later.

 
var linein = require("linein")({
  host: "http://api.site.com/v1/",
  mapResponsefunction(responsecallback) {
    if(response.result) {
      callback(null, response.result);
    } else {
      callback(response.error);
    }
  }
});
 
 
linen.register({
  students: {
    schema: {
      name: "string",
      email: "string"
    }
  },
  classes: {
    schema: {
      students: [{ $ref: "students" }] //classes/:class/students 
    }
  },
  teacher: {
    schema: {
      classes: [{ $ref: "classes" }]
    }
  }
});
 
var teacher = linen.map("teacher").item();
 
 
teacher.classes.at(0).students.at(1).name;
 
  • host - the API host
  • map -
  • name - the name of the endpoint
  • schema - the object schema for each item

creates a connection to a particular item served by the given endpoint.

  • name - the name of the endpoint
  • schema - the object schema

Fetches the contents of the current collection

Saves any unsaved items in the collection

returns an item in the collection

saves the item. If it's new, it'll send a POST request to the server. If it's not new, it'll send a PUT request.

removes the item

validates the object to make sure any unsaved data is correct