11

I have a simple CRUD app I am building in node, and have finished creating the rest API in Express. I am now looking to add front end functionality and wish to use react + redux as a learning exercise. It seems however all of the tutorials around this access the data directly using Redux, rather than interfacing with an internal API.

My question is, is that the correct way to build a SPA with redux? I was under the impression it was best to separate the front end from the backend so that I could, for example, build an iPhone app and not have to rebuild the backend.

Thanks in advance.

bpoiss
  • 13,673
  • 3
  • 35
  • 49
Dave
  • 113
  • 1
  • 2
  • 4

3 Answers3

12

Redux itself has nothing to do with API communication, it's the library for client-side state management. You can use whatever approach for firing and handling requests, most common are using custom api-connecting middleware, returning functions, which fire requests, from action-creators and using them with thunk-middleware or using alternative approaches like rx-bridges or sagas.

Victor Suzdalev
  • 2,202
  • 19
  • 28
  • That clears things up - thank you ever so much for the reply, and the suggested middleware. – Dave Feb 10 '16 at 14:40
2

Start with: https://egghead.io/series/getting-started-with-redux

Reffer to: What is best practice to communicate between React components and services?

Redux by design forces to build SPA application.

Community
  • 1
  • 1
Rafał Łyczkowski
  • 995
  • 2
  • 11
  • 27
1

First, see examples from redux docs, "Real World" is most useful: https://github.com/reactjs/redux/tree/master/examples/real-world

Then, you can research useful utils like redux-promise-middleware.

Finally, you can try to use some complex utils for connect your redux-app with API. redux-rest-adapter is one of them.

GoodTrip
  • 26
  • 3
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/18975041) – user3483203 Mar 01 '18 at 15:25
  • @chrisz I think this type of answer may be an exception. Reminds me of the top answer for [How do I get started with Node.js](https://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js#5511507) – BonsaiOak Mar 01 '18 at 15:31
  • @GoodTrip consider marking your answer as a community wiki so others can contribute. – BonsaiOak Mar 01 '18 at 15:31