request-json
Advanced tools
Comparing version 0.1.0 to 0.2.0
24
main.js
@@ -7,16 +7,24 @@ // Generated by CoffeeScript 1.3.3 | ||
exports.Client = (function() { | ||
exports.JsonClient = (function() { | ||
function Client(host) { | ||
function JsonClient(host) { | ||
this.host = host; | ||
} | ||
Client.prototype.get = function(path, callback) { | ||
JsonClient.prototype.get = function(path, callback) { | ||
return request({ | ||
method: "GET", | ||
headers: { | ||
'accept': 'application/json' | ||
}, | ||
uri: this.host + path | ||
}, callback); | ||
}, function(error, response, data) { | ||
if (typeof data === "string") { | ||
data = JSON.parse(data); | ||
} | ||
return callback(error, response, data); | ||
}); | ||
}; | ||
Client.prototype.post = function(path, json, callback) { | ||
JsonClient.prototype.post = function(path, json, callback) { | ||
return request({ | ||
@@ -29,3 +37,3 @@ method: "POST", | ||
Client.prototype.put = function(path, json, callback) { | ||
JsonClient.prototype.put = function(path, json, callback) { | ||
return request({ | ||
@@ -38,3 +46,3 @@ method: "PUT", | ||
Client.prototype["delete"] = function(path, callback) { | ||
JsonClient.prototype.del = function(path, callback) { | ||
return request({ | ||
@@ -46,3 +54,3 @@ method: "DELETE", | ||
return Client; | ||
return JsonClient; | ||
@@ -49,0 +57,0 @@ })(); |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/mycozycloud/request-json/", | ||
@@ -29,8 +29,11 @@ "bugs": { | ||
"main": "./main.js", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"request": "2.10.0" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "*" | ||
"coffee-script": "*", | ||
"chai": "*" | ||
}, | ||
"scripts": { | ||
"prepublish": "coffee --compile main.coffee" | ||
"prepublish": "cake build" | ||
}, | ||
@@ -37,0 +40,0 @@ "repository": { |
@@ -5,3 +5,22 @@ ## About | ||
it : simple get, pust, post and delete requests that carry only JSON. This lib | ||
simplifies Request for this usages. | ||
aims to simplify Request usage for these situations. | ||
## How it works | ||
```javascript | ||
Client = require("request-json").JsonClient | ||
client = new Client "http://localhost:8888/" | ||
client.post "posts/", { title: "my title", content:"my content" }, \ | ||
(error, response, body) -> | ||
print response.statusCode | ||
client.get "posts/", (error, response, body) -> | ||
print body.rows[0].title | ||
client.put "posts/123/", title: "my new title", (error, response, body) -> | ||
print response.statusCode | ||
client.del "posts/123/", (error, response, body) -> | ||
print response.statusCode | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3873
5
45
26
1
2
+ Addedrequest@2.10.0
+ Addedrequest@2.10.0(transitive)