Fetch Data from a Live Endpoint with RTK Query

Share this video with your friends

Social Share Links

Send Tweet

Currently our implementation just returns hardcoded data that we have in JSON. We want real data!

This lesson swaps out our hardcoded data for real endpoints.

Instructor: [0:00] Our next step is to really get this data from the server. We want to fetch the listing data from this URL. We get our result by awaiting fetch with this URL we just used and we get the data out of that by awaiting result.json. [0:28] Then, we return the data. This right now has no error handling. Let's do that too. If result is OK, we do this. Otherwise, we return an error. Something went wrong. Now, we can repeat the same for our other endpoint.

[0:55] Get the right URL here. If we look at the browser, let's get the data but now from the server.