Simulate Your Backend with a Proxy API

As we've been working through building up our application, we've done a ton of really great work but nearly all of it has been in this weird state where the data all lives completely inside of our React application. The reality is that this won't be true for most projects you work on, so we'll want to do a little bit of work to try to put the state of our Create React App project outside of React itself. To do that, we can take advantage of another feature in our Create React App world: proxy backends!

In addition, we'll need to spend a little bit of time talking about how we can actually get the data from that backend server into our Create React App project! A backend without a frontend isn't particularly useful, and vice versa! Similarly, a developer who has no understanding of either direction will be in a difficult situation, where they are designing systems with no sense of how they would need to interact with each other!

The simulated backend server we'll be building will act as the design document for our frontend developers to follow. It's not meant to be the final backend that we'll actually use, but rather, it will function as the framework that other developers can work with to better understand how to properly interact with our frontend and how to build a backend API that doesn't require us to completely rebuild our frontend!

In this chapter, we will cover the following topics:

  • Learning about the proxy feature
  • Implementing a quick Express.js server that should have a small footprint
  • Learning a little bit about the React component methods
  • Getting data in or out of our backend proxy via Fetch
  • Updating our tests

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset