Skip to content
This repository has been archived by the owner on Dec 23, 2018. It is now read-only.

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Condon committed Apr 6, 2015
1 parent 6b04dcf commit 9accd1a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 62 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
HTTP (api) adapter for [crudlet](http://github.com/mojo-js/crudlet.js).
HTTP (api) adapter for [mesh](http://github.com/mojo-js/mesh.js).

Simple example:

```javascript
var crudlet = require("crudlet");
var http = require("crudlet-http");
var db = crudlet.child(http(), {
var mesh = require("mesh");
var http = require("mesh-http");
var db = mesh.child(http(), {
prefix: "/api"
});

// POST /api/people
db(crud.op("insert", {
db(mesh.op("insert", {
collection: "people",
data: { name: "abba" }
}))

// this also works too:
db(crud.op("insert", {
db(mesh.op("insert", {
path: "/people",

// overridable
method: "POST",

// keep collection to make sure your API is interoperable
// with other crudlet adapters
// with other mesh adapters
collection: "people",
data: { name: "abba" }
}))
Expand All @@ -33,8 +33,8 @@ db(crud.op("insert", {

```javascript
var caplet = require("caplet");
var crud = require("crudlet")
var http = require("crudlet-http");
var mesh = require("mesh")
var http = require("mesh-http");
var _ = require("highland");

var db = http({
Expand Down Expand Up @@ -63,8 +63,8 @@ var db = http({
});

var dbs = {
tags : crud.child(db, { collection: "tags" }),
todos : crud.child(db, { collection: "todos" })
tags : mesh.child(db, { collection: "tags" }),
todos : mesh.child(db, { collection: "todos" })
};

/**
Expand All @@ -82,7 +82,7 @@ var Tags = caplet.createModelClass({

// GET /todos/:todo/tags
dbs
.tags(crud.op("load", {
.tags(mesh.op("load", {
owner: this.owner
}))
.pipe(_.pipeline(_.collect))
Expand Down Expand Up @@ -131,7 +131,7 @@ var Todo = caplet.createModelClass({

// GET /todos/:todo
dbs
.todos(crud.op("load", {
.todos(mesh.op("load", {
data: this
}))
.on("data", this.set.bind(this, "data"));
Expand All @@ -144,7 +144,7 @@ var Todo = caplet.createModelClass({

// POST or PUT
dbs
.todos(crud.op("upsert", {
.todos(mesh.op("upsert", {
data: this
}))
.on("data", this.set.bind(this, "data"));
Expand All @@ -160,7 +160,7 @@ var Todos = caplet.createCollectionClass({

// GET /todos
dbs
.todos(crud.op("load", { multi: true })).
.todos(mesh.op("load", { multi: true })).
.pipe(_.pipeline(_.collect))
.on("data", this.set.bind(this, "data"));
}
Expand All @@ -182,7 +182,7 @@ Performs a new operation on the API

- `options`
- `path` - (optional) path to the route - automatically resolved by collection if this is omitted
- `method` - (optional) resolved by CRUD method
- `method` - (optional) resolved by mesh method
- `headers` - (optional) HTTP headers


Expand All @@ -204,7 +204,7 @@ db("remove", {
Insert operation.

```javascript
var peopleDb = crud.child(db, { collection: "people" });
var peopleDb = mesh.child(db, { collection: "people" });

// resolves to POST /people with data as body
peopleDb("insert", { data: [{ name: "john"}, { name: "matt" }]}).on("data", function() {
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ gulp.task("bundle", function() {

gulp.task("minify", ["bundle"], function() {
return gulp.
src("./dist/crudlet.js").
src("./dist/mesh.js").
pipe(uglify()).
pipe(rename(function(path) {
path.basename += ".min";
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "crudlet-http",
"name": "mesh-http",
"version": "1.0.2",
"description": "local storage adapter (offline-mode) for crudlet",
"description": "local storage adapter (offline-mode) for mesh",
"main": "./lib/index.js",
"scripts": {
"test": "gulp lint test-coveralls"
},
"repository": {
"type": "git",
"url": "https://github.com/crcn/crudlet.js.git"
"url": "https://github.com/crcn/mesh.js.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/crcn/crudlet.js/issues"
"url": "https://github.com/crcn/mesh.js/issues"
},
"homepage": "https://github.com/crcn/crudlet.js",
"homepage": "https://github.com/crcn/mesh.js",
"devDependencies": {
"browserify": "^9.0.3",
"crudlet": "1.0.x",
"mesh": "1.0.x",
"expect.js": "^0.3.1",
"gulp": "^3.8.11",
"gulp-concat": "^2.5.2",
Expand Down
76 changes: 38 additions & 38 deletions test/http-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var http = require("..");
var crudlet = require("crudlet");
var mesh = require("mesh");
var expect = require("expect.js");

describe(__filename + "#", function() {
Expand All @@ -17,7 +17,7 @@ describe(__filename + "#", function() {
});

it("can customize the methods", function(next) {
var stream = crudlet.open(http({
var stream = mesh.open(http({
request: request,
method: function(operation) {
return {
Expand All @@ -36,65 +36,65 @@ describe(__filename + "#", function() {
next();
});

stream.write(crudlet.operation("insert", { path: "/ab" }));
stream.write(crudlet.operation("update", { path: "/ab" }));
stream.write(crudlet.operation("load", { path: "/ab" }));
stream.end(crudlet.operation("remove", { path: "/ab" }));
stream.write(mesh.operation("insert", { path: "/ab" }));
stream.write(mesh.operation("update", { path: "/ab" }));
stream.write(mesh.operation("load", { path: "/ab" }));
stream.end(mesh.operation("remove", { path: "/ab" }));

});

it("can run a get request", function(next) {
crudlet.open(http({ request: request })).on("end", function() {
mesh.open(http({ request: request })).on("end", function() {
expect(requests[0].method).to.be("post");
expect(requests[0].uri).to.be("/ab");
next();
}).end(crudlet.operation("insert", { path: "/ab" }));
}).end(mesh.operation("insert", { path: "/ab" }));
});

it("can pass params in the path", function(next) {
var stream = crudlet.stream(http({ request: request })).on("end", function() {
var stream = mesh.stream(http({ request: request })).on("end", function() {
expect(requests[0].uri).to.be("/blarg");
next();
}).end(crudlet.operation("insert", { data: { name: "blarg" }, path: "/:data.name" }));
}).end(mesh.operation("insert", { data: { name: "blarg" }, path: "/:data.name" }));
});

it("can have http specific params", function(next) {
var stream = crudlet.stream(http({ request: request })).
var stream = mesh.stream(http({ request: request })).
on("end", function() {
expect(requests[0].uri).to.be("/blarg");
next();
}).end(crudlet.operation("insert", { http: { data: { name: "blarg" }, path: "/:data.name" }}));
}).end(mesh.operation("insert", { http: { data: { name: "blarg" }, path: "/:data.name" }}));
});

it("path can be a function", function(next) {
var stream = crudlet.stream(http({ request: request })).
var stream = mesh.stream(http({ request: request })).
on("end", function() {
expect(requests[0].uri).to.be("/blarg");
next();
}).end(crudlet.operation("insert", { data: { name: "blarg" }, path: function(op) {
}).end(mesh.operation("insert", { data: { name: "blarg" }, path: function(op) {
expect(op.name).to.be("insert");
return "/:data.name";
}}));
});

it("method can be function", function(next) {
var stream = crudlet.stream(http({ request: request }));
var stream = mesh.stream(http({ request: request }));
stream.on("end", function() {
expect(requests[0].method).to.be("patch");
next();
});
stream.end(crudlet.operation("insert", { data: { name: "blarg" }, path:"/a", method: function(operation) {
stream.end(mesh.operation("insert", { data: { name: "blarg" }, path:"/a", method: function(operation) {
expect(operation.path).to.be("/a");
return "patch";
}}));
});

it("can use a transform function for the response", function(next) {
var stream = crudlet.stream(http({ request: request }));
var stream = mesh.stream(http({ request: request }));
stream.on("data", function(data) {
expect(data.data.name).to.be("blarg");
next();
}).end(crudlet.operation("insert", {
}).end(mesh.operation("insert", {
data: { name: "blarg" },
path: "/a",
transform: function(data) {
Expand All @@ -104,51 +104,51 @@ describe(__filename + "#", function() {
});

it("can provide custom http headers", function(next) {
var stream = crudlet.stream(http({ request: request }));
var stream = mesh.stream(http({ request: request }));

stream.on("end", function() {
expect(requests[0].headers.ua).to.be("b");
next();
});
stream.end(crudlet.operation("insert", { data: { name: "blarg" }, path:"/a", headers: { ua: "b" } }));
stream.end(mesh.operation("insert", { data: { name: "blarg" }, path:"/a", headers: { ua: "b" } }));
});

it("headers can be a function", function(next) {
var stream = crudlet.stream(http({ request: request }));
var stream = mesh.stream(http({ request: request }));
stream.on("end", function() {
expect(requests[0].headers.ua).to.be("b");
next();
});
stream.end(crudlet.operation("insert", { data: { name: "blarg" }, path:"/a", headers: function(operation) {
stream.end(mesh.operation("insert", { data: { name: "blarg" }, path:"/a", headers: function(operation) {
expect(operation.path).to.be("/a");
return { ua: "b" };
} }));
});

it("can add a query", function(next) {
var stream = crudlet.stream(http({ request: request }));
var stream = mesh.stream(http({ request: request }));
stream.on("end", function() {
expect(requests[0].uri).to.be("/a?ua=b");
next();
});
stream.end(crudlet.operation("insert", { data: { name: "blarg" }, path:"/a", query: {ua:"b"}}));
stream.end(mesh.operation("insert", { data: { name: "blarg" }, path:"/a", query: {ua:"b"}}));
});

it("query can be a function", function(next) {
var stream = crudlet.stream(http({ request: request }));
var stream = mesh.stream(http({ request: request }));
stream.on("end", function() {
expect(requests[0].uri).to.be("/a?ua=b");
next();
});
stream.end(crudlet.operation("insert", { data: { name: "blarg" }, path:"/a", query: function(operation) {
stream.end(mesh.operation("insert", { data: { name: "blarg" }, path:"/a", query: function(operation) {
expect(operation.path).to.be("/a");
return { ua: "b" };
} }));
});

it("automatically maps the path based on the collection", function(next) {

var stream = crudlet.stream(http({
var stream = mesh.stream(http({
request: request
}));

Expand All @@ -161,11 +161,11 @@ describe(__filename + "#", function() {
next();
});

stream.write(crudlet.operation("insert", { collection: "people", data: { uid: "1" }}));
stream.write(crudlet.operation("update", { collection: "people", data: { uid: "1" }}));
stream.write(crudlet.operation("load", { collection: "people", data: { uid: "1" }}));
stream.write(crudlet.operation("load", { collection: "people", multi: true, data: { uid: "1" }}));
stream.write(crudlet.operation("remove", { collection: "people", data: { uid: "1" }}));
stream.write(mesh.operation("insert", { collection: "people", data: { uid: "1" }}));
stream.write(mesh.operation("update", { collection: "people", data: { uid: "1" }}));
stream.write(mesh.operation("load", { collection: "people", data: { uid: "1" }}));
stream.write(mesh.operation("load", { collection: "people", multi: true, data: { uid: "1" }}));
stream.write(mesh.operation("remove", { collection: "people", data: { uid: "1" }}));
stream.end();

});
Expand All @@ -174,34 +174,34 @@ describe(__filename + "#", function() {
});

it("can add a prefix", function(next) {
var stream = crudlet.stream(http({
var stream = mesh.stream(http({
prefix: "/api",
request: request
}));
stream.on("end", function() {
expect(requests[0].uri).to.be("/api/people");
next();
});
stream.end(crudlet.operation("insert", { collection: "people", data: { uid: "1" }}));
stream.end(mesh.operation("insert", { collection: "people", data: { uid: "1" }}));
});

it("can add a prefix in the operation", function(next) {
var stream = crudlet.stream(http({
var stream = mesh.stream(http({
request: request
}));
stream.on("end", function() {
expect(requests[0].uri).to.be("/api/people");
next();
});
stream.end(crudlet.operation("insert", { prefix: "/api", collection: "people", data: { uid: "1" }}));
stream.end(mesh.operation("insert", { prefix: "/api", collection: "people", data: { uid: "1" }}));
});

it("can upsert and insert a value", function(next) {
var db = http({
request: request
});

db(crudlet.operation("upsert", {
db(mesh.operation("upsert", {
collection: "people",
data: { name: "a" }
})).on("end", function() {
Expand All @@ -216,7 +216,7 @@ describe(__filename + "#", function() {
request: request
});

db(crudlet.operation("upsert", {
db(mesh.operation("upsert", {
collection: "people",
data: { uid: "a" }
})).on("end", function() {
Expand Down

0 comments on commit 9accd1a

Please sign in to comment.