Make authenticated requests using Axios
Axios is a popular promise-based HTTP client. It can be used to transform and intercept HTTP request and response data asynchronously.
RequirementsAnchor link to section titled "Requirements"
Configure your Axios interceptorAnchor link to section titled "Configure your Axios interceptor"
- Install an interceptor to your instance of Axios.
Define a function that your Axios instance calls prior to each request.
The function takes a
configobject as parameter and returns a
configobject that's used as configuration for all subsequent requests.
In the function, call
getSessionToken()and resolve the token it returns.
configobject to append an
“Authorization”: “Bearer token”header to your requests, like in the following example:
- Learn how to use helper functions to fetch a session token from Shopify App Bridge and include them in requests being made to the app backend.
- Convert a multi-page, server-side rendered (SSR) app to use Shopify App Bridge authentication with Turbolinks.
- Learn how to build a Shopify app with Rails 6, React, and Shopify App Bridge authentication.