Vej.js (experimental)
Vej.js enables you to create a declarative layer on top of your HTTP library of choice.
Our goal is to allow you to define your resources whithout caring about the underlying HTTP library that's being used. So that you can later on replace it without having to change too much on your own code. You would only tell Vej what proxy to use given your new HTTP library.
Usage
Creating a resource
Calling the resource function will give you a function with a few inner functions that maps to four default HTTP verbs GET, POST, PATCH & DELETE
.
var jedis = vej; jedisall; // GET /jedisjedis; // POST /jedis {name: "Anakin Skywalker"}; // GET /jedis/anakin-skywalker; // PATCH /jedis/anakin-skywalker {name: "Darth Vader"}; // DELETE /jedis/luke-skywalker
Extending a resource
Vej lets your extend a resource with extra actions:
var jedis = vej; jedis; // GET /jedis/with_experience {lightsaber: "double"}jedis; // POST /jedis/send_to_battle {strategy: "peace & love"}jedis; // PATCH /jedis/stang_your_ground {formation: "cocoon"}jedis; // DELETE /jedis/fallback {with: "tail between your legs"} ; // GET /jedis/anakin/jedis_killed {which: "jedi"}; // POST /jedis/anakin/add_disciple {name: "star killer"}; // PATCH /jedis/anakin/change_lightsaber {color: "red"}; // DELETE /jedis/anakin/remove_rank {which: "jedi"}
Limiting resource creation
Vej allows you to limit the amount of actions created for a given resource.
Only
var jedis = vej; jedisall // GET /jedisjediscreate // undefineddetail // undefinedupdate // undefined // DELETE /jedis/luke-skywalker
Except
var jedis = vej; jedisall // undefinedjedis // POST /jedis {name: "Anakin"} // GET /jedis/anakin // PATCH /jedis/anakin {name: "Vader"}remove // undefined
Promises
Vej wraps every request with a promise (Promises/A+). We rely on then/promise to provide this functionality.
;