Using fetch to interact with unauthenticated REST API endpoints
In this section, we are going to use the native fetch
function to get unanswered questions from our real REST API. We are then going to use a wrapper function over fetch
to make interacting with our backend a little easier. This approach will also centralize the code that interacts with the REST API, which is beneficial when we want to make improvements to it. We'll then move on to using the real REST API to get a single question and search for questions.
Getting unanswered questions from the REST API
We are going to start interacting with the REST API on the home page when displaying the list of unanswered questions. The HomePage
component won't actually change, but the getUnansweredQuestions
function in QuestionsData.ts
will. In getUnansweredQuestions
, we'll leverage the native browser fetch
function...