0.0.17 • Published 9 years ago

restwrapper v0.0.17

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

#RestWrapper Build Status #Simple REST Calls for NODE/Browserify

Version: 0.0.17 I wrote this to be a simple way to communicate to REST Servers using the same syntax in my Node / Browserify applications.

It's a nice starting point for the mysterious WEB API often mentioned in FLUX tutorials.

URI can be parameterized according to http://tools.ietf.org/html/rfc6570

RestWrapper(uri, paramDefaults, headers);

paramDefaults - Populate the uri template variables from payload object by prefixing an '@' in the attributes value headers - pass any default headers as an object, ex {'secretToken':123}

Examples

var Message = new RestWrapper('http://example.com/messages/{messageID}', {messageID:'@id'});
Message.get({id:123}).then(function(message){
 alert(message.text);
});

or

Message.get({messageID: 123}).then(function(message){
 alert(message.text);
});
var newMessage = {text:"Hey, I think you're cool."};
Message.post(newMessage).then(function(message){
 alert('saved' + message.id).
});

var modifiedMessage = {id:123, text:"Heeeeeey"};//messageID is set from the id in the message object
Message.put(newMessage).then(function(message){
 alert('updated');
});

Feel free to tack on your own methods

Message.save = function(params,payload){
  if(payload.id){
     return this.put(params,payload);
  }else{
     return this.post(params,payload);
  }
};
0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago