ofetch icon indicating copy to clipboard operation
ofetch copied to clipboard

`body` vs `params` option

Open Dino-Kupinic opened this issue 1 year ago • 1 comments

Describe the change

In the documentation it is advised to use body with a POST request to pass data. Though in my Symfony API the user and password property were both null despite the payload containing them both. After looking through the code i saw the params option which worked.

Any plans on explaining this in the docs? I did not find the params option in the README

code in question:

const data = await $fetch("/login", {
    method: "POST",
    params: { usr: "user", pwd: "password" }, // body did not work
    baseURL: config.public.baseURL,
})

URLs

No response

Additional information

  • [X] Would you be willing to help?

Dino-Kupinic avatar May 02 '24 14:05 Dino-Kupinic

Invalid Issue / Question


params option is an alias for query. The payload you provided, (usr and pwd) were included in the URL query, instead of being sent as POST body. The final request was POST /login?usr=user&pwd=password. Unless you meant to transfer the payload via query, you should have used body instead. The issue is with your "Symfony API" not the ofetch library. Likely you are reading the body incorrectly there.

Aareksio avatar Jun 17 '24 14:06 Aareksio