在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:cozy/request-json开源软件地址:https://github.com/cozy/request-json开源编程语言:CoffeeScript 100.0%开源软件介绍:AboutRequest is a great HTTP client for NodeJS, but if you deal only with JSON, things could be more straightforward. This lib aims to simplify Request usage for JSON only requests. InstallAdd it to your package.json file or run in your project folder:
Build statusHow it worksrequest = require('request-json');
var client = request.createClient('http://localhost:8888/');
var data = {
title: 'my title',
content: 'my content'
};
client.post('posts/', data, function(err, res, body) {
return console.log(res.statusCode);
});
client.get('posts/', function(err, res, body) {
return console.log(body.rows[0].title);
});
data = {
title: 'my new title'
};
client.put('posts/123/', data, function(err, res, body) {
return console.log(res.statusCode);
});
client.del('posts/123/', function(err, res, body) {
return console.log(res.statusCode);
});
data = {
title: 'my patched title'
};
client.patch('posts/123/', data, function(err, res, body) {
return console.log(res.statusCode);
}); Note: Previously you should call Extra: filesdata = {
name: "test"
};
client.sendFile('attachments/', './test.png', data, function(err, res, body) {
if (err) {
return console.log(err);
}
});
client.saveFile('attachments/test.png', './test-get.png', function(err, res, body) {
if (err) {
return console.log(err);
}
});
Extra: basic authenticationclient.setBasicAuth('john', 'secret');
client.get('private/posts/', function(err, res, body) {
return console.log(body.rows[0].title);
}); Extra: headers manipulationclient.headers['Cookie'] = 'Your cookie'; Extra: promisesclient.get('posts/')
.then(function(result) {
console.log(result.res.statusCode);
console.log(result.body);
}).catch(err) {
console.log(err);
}
}); Who uses itrequest-json and request-json-light are downloaded more than 50 000 times each month. Here are the companies which use it for their API clients:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论