Skip to content

node-fetchvsnestful

MIT 241 10 8,860
553.6 million (month) Dec 28 2012 3.3.2(2023-11-30 14:10:12 ago)
505 3 11 NA
Apr 20 2010 55.0 thousand (month) 1.1.4(2020-02-07 22:04:51 ago)

node-fetch is a lightweight library that provides a fetch()-like API for making HTTP requests in Node.js. It is a light-weight implementation of the Fetch API, which is mostly compatible with the browser's version.

node-fetch is primarily known as almost identical package fetch() is included in web browsers so it shares the same use common API. It's great starting point for people coming from front-end environment.

Nestful is a Ruby library for making HTTP requests. It is designed to provide a simple, easy-to-use interface for making requests and handling responses. Nestful is often used for making requests to RESTful APIs.

One of the main features of Nestful is its ability to automatically parse JSON and XML responses and return them as Ruby objects. This allows developers to easily access the data returned by an API without having to manually parse the response.

Netful is aimed at interacting with rest APIs and provides a convenient interface (see example below)

Highlights


popular

Example Use


```javascript const fetch = require('node-fetch'); // fetch supports both Promises and async/await fetch('http://httpbin.org/get') .then(res => res.text()) .then(body => console.log(body)) .catch(err => console.error(err)); const response = await fetch('http://httpbin.org/get'); // for concurrent scraping Promise.all can be used const results = await Promise.all([ fetch('http://httpbin.org/html'), fetch('http://httpbin.org/html'), fetch('http://httpbin.org/html'), ]) // POST requests await fetch('http://httpbin.org/post', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'John Doe' }), }) // Proxy use: const agent = new https.Agent({ rejectUnauthorized: false, proxy: { host: 'proxy.example.com', port: 8080 } }); await fetch('https://httpbin.org/ip', { agent }) // setting headers and cookies const headers = new fetch.Headers(); headers.append('Cookie', 'myCookie=123'); headers.append('X-My-Header', 'myValue'); await fetch('https://httpbin.org/headers', { headers }) ```
```ruby require 'nestful' # GET request response = Nestful.get('http://httpbin.org/get') puts response.body puts response.code puts response.headers # POST request response = Nestful.post( 'http://httpbin.org/post', :format => :json, :payload => { :title => 'foo', :body => 'bar', :userId => 1 } ) puts response.body # establish interface to a specific API class Charge < Nestful::Resource endpoint 'https://api.stripe.com/v1/charges' options :auth_type => :bearer, :password => 'sk_bar' def self.all self.new(get) end def self.find(id) self.new(get(id)) end def refund post(:refund) end end Charge.all #=> [] Charge.find('ch_bar').amount ```

Alternatives / Similar


Was this page helpful?