All Projects → pedrotcaraujo → wobbuffetch

pedrotcaraujo / wobbuffetch

Licence: MIT License
Reactive wrapper for Fetch API

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to wobbuffetch

Node Fetch
A light-weight module that brings the Fetch API to Node.js
Stars: ✭ 7,176 (+25528.57%)
Mutual labels:  http-client, fetch-api
fetch-wrap
extend WHATWG fetch wrapping it with middlewares
Stars: ✭ 21 (-25%)
Mutual labels:  http-client, fetch-api
Php Fetch
A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP
Stars: ✭ 95 (+239.29%)
Mutual labels:  http-client, fetch-api
Firefly
Firefly is an asynchronous web framework for rapid development of high-performance web application.
Stars: ✭ 277 (+889.29%)
Mutual labels:  http-client, reactive-programming
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (+21.43%)
Mutual labels:  http-client, fetch-api
Cross Fetch
Universal WHATWG Fetch API for Node, Browsers and React Native.
Stars: ✭ 1,063 (+3696.43%)
Mutual labels:  http-client, fetch-api
Rx.Http
A reactive way to make HTTP Request in .NET Core 🚀
Stars: ✭ 62 (+121.43%)
Mutual labels:  http-client, reactive-programming
monolog-http
A collection of monolog handlers that use a PSR-18 HTTP Client to send your logs
Stars: ✭ 34 (+21.43%)
Mutual labels:  http-client
queueable
Convert streams to async ⌛ iterables ➰
Stars: ✭ 43 (+53.57%)
Mutual labels:  reactive-programming
nativescript-http
The best way to do HTTP requests in NativeScript, a drop-in replacement for the core HTTP with important improvements and additions like proper connection pooling, form data support and certificate pinning
Stars: ✭ 32 (+14.29%)
Mutual labels:  http-client
rq
A nicer interface for golang stdlib HTTP client
Stars: ✭ 40 (+42.86%)
Mutual labels:  http-client
openapiclientgen
Generate C# and TypeScript client codes from Open API / Swagger definitions
Stars: ✭ 31 (+10.71%)
Mutual labels:  fetch-api
googlemaps-services
📍Ruby client library for Google Maps API Web Services
Stars: ✭ 14 (-50%)
Mutual labels:  http-client
gohttp
A simple to use golang http client
Stars: ✭ 47 (+67.86%)
Mutual labels:  http-client
Mp3ID3Tagger
🎶🎵A macOS application to edit the ID3 tag of your mp3 files. Developed with RxSwift and RxCocoa. 🎸🎼
Stars: ✭ 17 (-39.29%)
Mutual labels:  reactive-programming
CombineCoreBluetooth
A wrapper API for CoreBluetooth using Combine Publishers
Stars: ✭ 50 (+78.57%)
Mutual labels:  reactive-programming
react-mobx-router5
React components for routing solution using router5 and mobx
Stars: ✭ 58 (+107.14%)
Mutual labels:  reactive-programming
reacted
Actor based reactive java framework for microservices in local and distributed environment
Stars: ✭ 17 (-39.29%)
Mutual labels:  reactive-programming
dspatch
The Refreshingly Simple Cross-Platform C++ Dataflow / Pipelining / Stream Processing / Reactive Programming Framework
Stars: ✭ 124 (+342.86%)
Mutual labels:  reactive-programming
fetchx
Beautiful way to fetch data in React
Stars: ✭ 71 (+153.57%)
Mutual labels:  http-client

Wobbuffet

wobbuffetch

Build Status Coverage Status js-standard-style

Reactive wrapper for HTTP requests using Fetch API

Why

Handling asynchronous and event-based requests is boring. Sometimes we need to manipulate data loaded from a server with only what we need, merge, debounce, distinct and so on. Wobbuffetch is a reactive http library that wraps Fetch API along with a set of observable collections that make your life easier.

Features

  • Easy to use
  • Fetch API features
  • Observable api collections (RxJS)
  • Automatic transforms for JSON data
  • Runs from browser and server

Learn

Installing

Via npm:

$ npm install wobbuffetch

Via cdn:

<script src="https://unpkg.com/wobbuffetch/dist/wobbuffetch.min.js"></script>

How to use

GET example:

import wfetch from 'wobbuffetch';

/* api data posts
"posts": [
    {
      "id": 1,
      "title": "FRP for life",
      "author": "anonymous"
    },
    {
      "id": 2,
      "title": "Imperative programming from hell",
      "author": "Demo"
    }
  ]
*/

wfetch.get('http://api.mydomain.com/posts').subscribe(res => console.log(res))

/* response:
{
  data: [
    { "id": 1, "title": "FRP for life", "author": "anonymous" },
    { "id": 2, "title": "Imperative programming from hell", "author": "Demo" }
  ],
  status: 200,
  statusText: 'Ok',
  headers: { Content-Type: application/json },
}
*/

wfetch.get('http://api.mydomain.com/posts').flatMap(res => res.data).subscribe(post => console.log(post))

/* response with flatMap:
  { "id": 1, "title": "FRP for life", "author": "anonymous" },
  { "id": 2, "title": "Imperative programming from hell", "author": "Demo" }
*/

POST example:

wfetch.post('http://api.mydomain.com/posts' {
  data: {
    title: 'How Reactive js works',
    author: 'You'
  }}).subscribe(res => console.log(res))

/* response:
{
  data: { "id": 3, "title": "How wobbuffetch js works", "author": "You" },
  status: 200,
  statusText: 'Ok',
  headers: { Content-Type: application/json },
}
*/

wfetch.post('http://api.mydomain.com/posts' {
  data: {
    title: 'Wobbuffetch js is handy',
    author: 'me'
  }}).map(res => res.data.title).subscribe(title => console.log(title))

/* response with map:
  'Wobbuffetch js is handy'
*/

Error handling:

function _success(response) {
  console.log(`Success: ${response.status}`)
}

function _error({ response }) {
  console.log(`Error: ${response.status}`)
}


wfetch.get('http://mydomain/api/posts/30').subscribe(_success, _error)

/* response Error:
  'Error: 404'
*/

To learn more see RxJS from promise.

Default configuration

We often need to set additional request options, but some of them are default in the wobbuffetch library. For more information and options check out Fetch API options.

An important change in Fetch API is that the option body is now data in wobbuffetch.

{
  baseUrl: '', // Base URL to use in every request
  headers: { 'Content-Type': 'application/json' }, // Fetch API:  Object literal as headers
  credentials: 'same-origin', // Fetch API: Only send cookies if the URL is from the same origin as the calling script.
  cache: 'default',  // Fetch API:  The browser looks for a matching request in its HTTP cache.
  responseType: 'json', // Methods to extract the body from the response (ex: 'arrayBuffer', 'blob', 'json', 'text')
  // Defines if the response will be resolved or rejected given a status.
  validateStatus: function (status) {
    return status >= 200 && status < 300
  }
}

Config default:

import wfetch from 'wobbuffetch';

wfetch.defaults.baseURL = 'http://api.mydomain.com'
wfetch.defaults.headers = { 'Content-Type': 'text/xml' }
wfetch.defaults.responseType = 'text'

Response schema

{
	status: 200, // HTTP status code from the server
	statusText: 'OK', // HTTP status message from the server
	headers: {}, // Headers from the server
	data: {}, // Response data requested from the server ( 'HEAD' method does not receive this)
}

Methods

Instance methods: wobbuffetch#method(url[, config])

GET

wobbuffetch.get('http://api.mydomain.com/posts').subscribe(res => {
	// Do something ...
})

with params:

wobbuffetch.get('http://api.mydomain.com/posts', { // http://api.mydomain.com/posts?title=you
	params: { title: 'you' }
}).subscribe(res => {
	// Do something ...
})

HEAD

// Method 'head' has no 'data'
wobbuffetch.head('http://api.mydomain.com/posts').subscribe(res => {
	console.log(res.data) // undefined
})

DELETE

wobbuffetch.delete('http://api.mydomain.com/posts/1').subscribe(res => {
	// Do something ...
})

POST

// Wobbuffetch there is no options 'body' anymore, use 'data' instead
wobbuffetch.post('http://api.mydomain.com/posts', {
	data: { // It can receives object literal now
		title: 'something',
		author: 'unknown'
	}
}).subscribe(res => {
	// Do something ...
})

PUT

// Wobbuffetch has no option 'body' anymore, use 'data' instead
wobbuffetch.put('http://api.mydomain.com/posts', {
	data: { // It can receive object literals now
		title: 'something',
		author: 'unknown'
	}
}).subscribe(res => {
	// Do something ...
})

PATCH

// Wobbuffetch has no option 'body' anymore, use 'data' instead
wobbuffetch.patch('http://api.mydomain.com/posts', {
	data: { // It can receives object literal now
		title: 'something',
		author: 'unknown'
	}
}).subscribe(res => {
	// Do something ...
})

by

@pedrotcaraujo

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].