Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between axios({method: "post"}) and axios.post()

I'm using Shopify Storefront API and Axios to develop locally a e-shop.

Shopify give me a response when I use axios(), but it returns 403 Forbidden when I do the same thing with axios.post().

What's the difference between those two?

axios.post(
    SHOPIFY_DOMAIN,
    {
    headers: {
        "Content-Type": "application/graphql",
        "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
    },
    data: `{ shop }`
})
axios({
  method: "post",
  url: SHOPIFY_DOMAIN,
  headers: {
    "Content-Type": "application/graphql",
    "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
  },
  data: `{ shop }`
})
like image 887
a.barbieri Avatar asked Nov 07 '22 08:11

a.barbieri


1 Answers

The declaration of axios.post is axios.post(url[, data[, config]]). The correct way of using is:

axios.post(
    SHOPIFY_DOMAIN,
    `{ shop }`,
    {
        headers: {
            "Content-Type": "application/graphql",
            "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
        }
    }
);

See also: axios API

like image 190
Ben Avatar answered Nov 14 '22 23:11

Ben