The best API is no API — introducing React Remote Redux

Severin Ibarluzea
3 min readAug 24, 2018

--

You’re a full stack developer, you want to build applications fast, you like Redux and you use React. Normally, you’d throw together a React client side application, a redux store to manage state, a RESTful API, and asynchronous bindings to connect your store to your REST API. Well that could be a lot simpler.

Remote Redux moves part of your store to the server so you don’t have to create an API or bindings.

In Remote Redux, we send some actions to the server to compute the next state. In practice it’s a lot like using a React Redux Provider, except we provide an endpoint where actions can be sent to perform the state transition.

Certain actions are sent to the server to perform the state transition.

Using React Remote Redux, the endpoint receives two parameters in a POST request, the state and the action. All it has to do is compute the next state and return it in the body of the response.

In Remote Redux there are two types of reducers. A local reducer is executed on the browser and must be synchronous. A remote reducer is executed on the server and can be asynchronous. The function signatures are exactly the same, except a remote reducer can return a Promise.

Remote Reducers look very similar to local reducers.

This makes a lot of things easier, let’s say we want to perform a search. Our remote reducer might look like this…

A Remote Reducer can use a database because it can be asynchronous (SQL sanitized by KnexJS)

It may not seem like it, but we just saved a ton of time avoid writing a REST API endpoint and the corresponding Redux API bindings (where we would have to introduce something like Redux Sagas or Observables).

Remote Redux is very powerful, it can drastically reduce the amount of client-side and server-side code, simplify APIs and execute actions in parallel using predictive reduction.

I’ve been using Remote Redux in production for about 6 months. I think it’s a great candidate for early applications, especially because it’s very easy to swap out if you decide to use a RESTful API later. Check out React Remote Redux here, I’d love to hear your thoughts!

More where this came from

This story is published in Noteworthy, where thousands come every day to learn about the people & ideas shaping the products we love.

Follow our publication to see more product & design stories featured by the Journal team.

--

--