0.0.17 • Published 10 years ago

restwrapper v0.0.17

Weekly downloads
4
License
MIT
Repository
github
Last release
10 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

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago