1.0.4 • Published 8 years ago
fettuccine v1.0.4
fettuccine
A simplified HTTP client for Node
- with the Promise API
- and every imaginable option thanks to Request,
- nevertheless, keeping small package size by economical module loading
const fettuccine = require('fettuccine');
(async () => {
const response = await fettuccine('https://api.github.com/users/isaacs/repos', {
qs: {sort: 'created'},
json: true
});
response.body[0]; //=> {id: 46883374, name: 'pseudomap', ...}
})();Installation
npm install fettuccineAPI
const fettuccine = require('fettuccine');fettuccine(url , options)
url: string (URL to send a request)
options: Object (used as Request options with gzip defaulting to true)
Return: Promise<Object>
It makes an HTTP or HTTPS request to the given URL.
When the request finishes, it will be fulfilled with the http.IncomingMessage object with the additional body property:
responsebody (StringorBuffer, or JSON object if thejsonoption is supplied)
When the request fails, it will be rejected with an error object (usually from http.ClientRequest object).
fettuccine.get()
Alias of fettuccine().
fettuccine.post(), fettuccine.put(), fettuccine.patch(), fettuccine.head(), fettuccine.delete()
Set options.method to the method name and call fettuccine().
const fettuccine = require('fettuccine');
// With `fettuccine()`
(async () => {
await fettuccine('https://awesome-webservice.com/api', {
method: 'POST',
body: imageBuffer
});
console.log('Uploaded an image.')
})();
// With `fettuccine.post()`
(async () => {
await fettuccine.post('https://awesome-webservice.com/api', {
body: imageBuffer
});
console.log('Uploaded an image.')
})();fettuccine.Fettuccine(options)
The Fettuccine class.
License
ISC License © 2018 Shinnosuke Watanabe