Skip to main content
Version: next

Axios instances

This reference explains how to create `axios` instances to interact with Magento's API.

WIP
  • makeAdminClientFromRequest

makeUserClientFromRequest

The makeUserClientFromRequest function creates an axios instance that can be used to interact with Magento's API as a customer.

makeUserClientFromRequest(request);

Arguments:

NameTypeDescription
requestRequestv2 compatible request object

Example:

import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeUserClientFromRequest } from "@front-commerce/magento2/axios";

export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const axiosInstance = makeUserClientFromRequest(req);

// rest of logic
},
});

makeCartUrlBuilderFromRequest

The makeCartUrlBuilderFromRequest function creates a CartUrlBuilder instance.

makeCartUrlBuilderFromRequest(request);

Arguments:

NameTypeDescription
requestRequestv2 compatible request object

Example:

import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeCartUrlBuilderFromRequest } from "@front-commerce/magento2/axios";

export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const cartUrlBuilder = makeCartUrlBuilderFromRequest(req);

// rest of logic
},
});