Socket
Socket
Sign inDemoInstall

request-json

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-json - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

Cakefile

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
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc