Authenticating Requests
Learn to make authenticated requests to REST API endpoints using bearer tokens.
We'll cover the following
Making authenticated HTTP requests
In most cases, we will be interacting with endpoints that require some form of authentication and possibly authorization for us to fetch or make changes to resources. Therefore, we would need to send the user’s credentials with a request to validate that it is coming from a known source.
There are several different ways to authenticate REST API requests. In our case, we will use bearer authentication, which is the most commonly used form of authentication. This authentication method involves security tokens, commonly known as bearer tokens, attached to a request’s Authorization
header.
How to authenticate requests
To make authenticated requests:
- Log in to the API on an authentication endpoint and get back a token.
- Save the token on disk (we will explore this in the Data Persistence Concepts lesson).
- Supply the token in the protected API endpoints’ headers.
Let’s see how to implement this using our mock API service.
Test the sample requests in the app below:
Get hands-on with 1400+ tech skills courses.