Using Fetch to Interact With Authenticated REST API Endpoints
Learn to interact with authenticated REST API using the fetch function.
We'll cover the following
We'll properly wire up posting questions and answers to our REST API. As part of this work, we will enhance our http
function to use a bearer token from Auth0 in the HTTP request. This is because the endpoints for posting questions and answers are protected in the REST API and require a valid bearer token.
All of our changes will be in QuestionsData.ts
—our user interface components will be unchanged.
Posting a question to the REST API
We are going to change the implementation for posting a question to use an access token from Auth0:
Let's start by importing the function that gets the access token from Auth0 into
QuestionsData.ts
:
Get hands-on with 1400+ tech skills courses.