All Projects → klis87 → Redux Requests

klis87 / Redux Requests

Licence: mit
Declarative AJAX requests and automatic network state management for single-page applications

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Redux Requests

Rxios
A RxJS wrapper for axios
Stars: ✭ 119 (-63.94%)
Mutual labels:  axios, http-client, frontend, front-end
Bit
A tool for component-driven application development.
Stars: ✭ 14,443 (+4276.67%)
Mutual labels:  graphql, frontend, front-end, monorepo
Saber
⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
Stars: ✭ 866 (+162.42%)
Mutual labels:  axios, http-client, ajax
Jiny
Lightweight, modern, simple JVM web framework for rapid development in the API era
Stars: ✭ 40 (-87.88%)
Mutual labels:  websocket, http-client, websocket-client
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+916.67%)
Mutual labels:  websocket, http-client, websocket-client
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+882.12%)
Mutual labels:  websocket, http-client, websocket-client
Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+592.42%)
Mutual labels:  http-client, ajax, fetch
Web Interview
我是「齐丶先丶森」,公众号「前端面试秘籍」作者,收集整理全网面试题及面试技巧,旨在帮助前端工程师们找到一份好工作!
Stars: ✭ 1,230 (+272.73%)
Mutual labels:  ajax, frontend, front-end
cute-http
一个基于axios封装的更易用的http库。
Stars: ✭ 18 (-94.55%)
Mutual labels:  ajax, http-client, axios
vue-methods-promise
Let Vue methods support return Promise
Stars: ✭ 35 (-89.39%)
Mutual labels:  fetch, ajax, axios
Kunafa
Easy to use, high level framework in Kotlin for front-end web-development
Stars: ✭ 148 (-55.15%)
Mutual labels:  frontend, front-end, single-page-app
electron-request
Zero-dependency, Lightweight HTTP request client for Electron or Node.js
Stars: ✭ 45 (-86.36%)
Mutual labels:  fetch, ajax, http-client
Gun
HTTP/1.1, HTTP/2 and Websocket client for Erlang/OTP.
Stars: ✭ 710 (+115.15%)
Mutual labels:  websocket, http-client, websocket-client
Hoppscotch
👽 Open source API development ecosystem https://hoppscotch.io
Stars: ✭ 34,569 (+10375.45%)
Mutual labels:  graphql, websocket, http-client
fetchx
Beautiful way to fetch data in React
Stars: ✭ 71 (-78.48%)
Mutual labels:  fetch, http-client, axios
Thwack
A tiny modern data fetching solution
Stars: ✭ 268 (-18.79%)
Mutual labels:  axios, ajax, fetch
Insomnia
The open-source, cross-platform API client for GraphQL, REST, and gRPC.
Stars: ✭ 18,969 (+5648.18%)
Mutual labels:  graphql, http-client
Ws
Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
Stars: ✭ 17,419 (+5178.48%)
Mutual labels:  websocket, websocket-client
Translate
阿里云翻译小组,为社区输出优质的技术文章。
Stars: ✭ 293 (-11.21%)
Mutual labels:  graphql, frontend
Saleor Dashboard
A GraphQL-powered, single-page dashboard application for Saleor.
Stars: ✭ 278 (-15.76%)
Mutual labels:  graphql, single-page-app

Redux-Requests

npm version gzip size dependencies dev dependencies peer dependencies Build Status Coverage Status Known Vulnerabilities lerna code style: prettier

Declarative AJAX requests and automatic network state management for single-page applications

Redux-Requests showcase

Table of content

Motivation ⬆️

With redux-requests, assuming you use axios (you could use it with anything else too!) you could refactor a code in the following way:

  import axios from 'axios';
- import thunk from 'redux-thunk';
+ import { handleRequests } from '@redux-requests/core';
+ import { createDriver } from '@redux-requests/axios'; // or another driver

  const FETCH_BOOKS = 'FETCH_BOOKS';
- const FETCH_BOOKS_SUCCESS = 'FETCH_BOOKS_SUCCESS';
- const FETCH_BOOKS_ERROR = 'FETCH_BOOKS_ERROR';
-
- const fetchBooksRequest = () => ({ type: FETCH_BOOKS });
- const fetchBooksSuccess = data => ({ type: FETCH_BOOKS_SUCCESS, data });
- const fetchBooksError = error => ({ type: FETCH_BOOKS_ERROR, error });

- const fetchBooks = () => dispatch => {
-   dispatch(fetchBooksRequest());
-
-   return axios.get('/books').then(response => {
-     dispatch(fetchBooksSuccess(response.data));
-     return response;
-   }).catch(error => {
-     dispatch(fetchBooksError(error));
-     throw error;
-   });
- }

+ const fetchBooks = () => ({
+   type: FETCH_BOOKS,
+   request: {
+     url: '/books',
+     // you can put here other Axios config attributes, like method, data, headers etc.
+   },
+ });

- const defaultState = {
-   data: null,
-   pending: 0, // number of pending FETCH_BOOKS requests
-   error: null,
- };
-
- const booksReducer = (state = defaultState, action) => {
-   switch (action.type) {
-     case FETCH_BOOKS:
-       return { ...defaultState, pending: state.pending + 1 };
-     case FETCH_BOOKS_SUCCESS:
-       return { ...defaultState, data: action.data, pending: state.pending - 1 };
-     case FETCH_BOOKS_ERROR:
-       return { ...defaultState, error: action.error, pending: state.pending - 1 };
-     default:
-       return state;
-   }
- };

  const configureStore = () => {
+   const { requestsReducer, requestsMiddleware } = handleRequests({
+     driver: createDriver(axios),
+   });
+
    const reducers = combineReducers({
-     books: booksReducer,
+     requests: requestsReducer,
    });

    const store = createStore(
      reducers,
-     applyMiddleware(thunk),
+     applyMiddleware(...requestsMiddleware),
    );

    return store;
  };

Features ⬆️

Just actions

Just dispatch actions and enjoy automatic AJAX requests and network state management

First class aborts support

Automatic and configurable requests aborts, which increases performance and prevents race condition bugs before they even happen

Drivers driven

Compatible with anything for server communication. Axios, Fetch API, GraphQL, promise libraries, mocking? No problem! You can also integrate it with other ways by writing a custom driver!

Batch requests

Define multiple requests in single action

Optimistic updates

Update remote data before receiving server response to improve perceived performance

Cache

Cache server response forever or for a defined time period to decrease amount of network calls

Data normalisation

Use automatic data normalisation in GraphQL Apollo fashion, but for anything, including REST!

Server side rendering

Configure SSR totally on Redux level and write truly universal code between client and server

React bindings

Use react bindings to decrease code amount with React even more

Typescript friendly

It has many utilities to make Typescript experience even greater, for example all data generics are inferred in selectors and dispatch results automatically.

Installation ⬆️

To install the package, just run:

$ npm install @redux-requests/core

or you can just use CDN: https://unpkg.com/@redux-requests/core.

Also, you need to install a driver:

  • if you use Axios, install axios and @redux-requests/axios:

    $ npm install axios @redux-requests/axios
    

    or CDN: https://unpkg.com/@redux-requests/axios.

  • if you use Fetch API, install isomorphic-fetch (or a different Fetch polyfill) and @redux-requests/fetch:

    $ npm install isomorphic-fetch redux-requests/fetch
    

    or CDN: https://unpkg.com/@redux-requests/fetch.

Also, you have to install reselect, which probably you use anyway.

Usage ⬆️

For usage, see documentation

Examples ⬆️

I highly recommend to try examples how this package could be used in real applications. You could play with those demos and see what actions are being sent with redux-devtools.

There are following examples currently:

Companion libraries ⬆️

  • redux-smart-actions - Redux addon to create actions and thunks with minimum boilerplate, you can use it to create requests actions faster and in a less verbose way, without constants, useful especially to create thunks without constants, so you have access to Redux state in request actions without any need to pass them with action arguments

Licence ⬆️

MIT

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].