ilonacodes
Patreon
Investor Profile
Contact

Financial tips and advice on investment for developers:
"Learn how to free extra monthly cash from your dev-salary for investment"

There are so many different ways to free money for investments without thinking of getting another job. Download my Top-15 cash-freeing tips cheat sheet.

Get my 15 Tips to Invest More Cash Monthly!
17
Mar
2018
#react
#redux
#fetch
#javascript
#frontend
#learntocode
#coding
#letsgetcoding
#womenwhocode

Front-end Shorts: Fetch List of Resources From REST-API

17 Mar, 2018

Today I am going to tell you how to get JSON data from the Rest-API to UI using React+Redux frameworks.

In my case, the task looks like:

I have a URL, for example: https://api.com/v1/expenses/ which will give the following JSON data, and I want to get this data in my UI.

To solve this task, I decided to use JavaScript’s fetch method. So in this way, I shouldn’t rely on any external libraries (given my target browsers are remotely up-to-date).

What is nice, that by default the fetch method uses GET and I don’t have to specify any options, however, you can do all that if you want. For further reference: Fetch API reference.

Let’s look at the following code snippet of my implementation:


const loadExpenses = () => {
       fetch('https://api.com/v1/expenses/')
            .then(response => response.json())
            .then(expenses => loadedExpenses(expenses))
};

*loadedExpenses is a function that dispatches action to Redux and then reducer stores the data in the store.

Thank you for reading and have a lovely weekend!

Tags | #react #redux #fetch #javascript #frontend #learntocode #coding #letsgetcoding #womenwhocode
Next: Front-end Shorts: Setting up React-Router-Redux

My name is Ilona, and I'm a software engineer, founder, and blogger who is (besides programming) also passionate about startups, finance and investment

"I like to work hard for things that are worth it."
The latest articles:
Numbrs Review - App For Personal Finances (Germany & UK only)
How Developers Can Get Symbols From Stock Indexes With Python
Bitcoin Profit Calculator For Developers

Imprint
Privacy Policy
© 2021 ilonacodes
© 2021 ilonacodes
Imprint
Privacy Policy