Categories
Vue Answers

How to send JSON web token (JWT) in an Axios GET request?

Spread the love

Sometimes, we want to send JSON web token (JWT) in an Axios GET request.

In this article, we’ll look at how to send JSON web token (JWT) in an Axios GET request.

How to send JSON web token (JWT) in an Axios GET request?

To send JSON web token (JWT) in an Axios GET request, we can add it to the headers.

For instance, we write

<script>
export default {
  //...
  get() {
    const url = "...";
    const token = "...";
    const config = {
      headers: {
        Authorization: `Bearer ${token}`,
      },
    };
    axios.get(url, config);
  },
  //...
};
</script>

to call axios.get with the url and config.

In config, we add the headers by setting the headers property to an object that has the Authorization header set to the token value.

Conclusion

To send JSON web token (JWT) in an Axios GET request, we can add it to the headers.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *