developit / redaxios

The Axios API, as an 800 byte Fetch wrapper.

Home Page:https://npm.im/redaxios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lower case method?

bsdis opened this issue · comments

commented

when i do redaxios.patch, i can see that its translated to patch and not PATCH which gives problems in terms of 400 bad request.

Looking through the redaxios code this seems intentional. Why? According to RFC 7231 page 21. 1) the table uses capital case and doesn't say anywhere that variations of the values in the table are allowed. 2) last sentence on page 20
methods are case sensitive and should be upper case.

Am I missing something here?

Can you give an example where this produces an error? Lowercase HTTP method names are allowed by fetch() and should be transformed to uppercase prior to issuing the network request. Perhaps you're using a fetch polyfill that isn't doing this correctly?

commented

i used .patch method and got 404 bad request error. I dont think i used any polyfills...i just used redaxios out of the box. As soon as i switched back to normal axios.patch it worked great and where redaxios produced a patch request, axios produced a PATCH request and its been working since

What server/service is producing the 400?

commented

its a 404... the error already seemed to come before request even was transmitted to the server.
Almost asif the browser halted it even.
I am using a django backend

tbh that really does sound like a polyfill then. Are you able to provide any details about your frontend setup? Are you using a build tool or off-the-shelf setup like Next.js, create-react-app, Vue CLI, etc?

commented

I can confirm the bad request issue. My backend is Node.JS with Express.

browserslist (used by babel, postcss, etc.) is > 5% in my project. That means:

and_chr 86
chrome 86
chrome 85
ios_saf 14

I don't have any additional polyfill configuration in my project. Thus, it is extremely unlikely that the issue is related to polyfill.

Why not just simply use the upper case? It is more conforming and just makes more sense.

commented

i have switched back to standard axios because of this and other suspicious behaviours

@developit facing this issue as well. I have a repro with json-server with CRA here that faces this with patch.

Replacing axios with redaxios will highlight the issue.

Same problem with nextjs v10.1.3 and redaxios 0.4.1 as unique dependency (besides react). According their docs polyfills are only included if browser does not support fetch.

Using patch method convert the method to lowercase, but using axios as a function works well.

// it works
await axios('/my-patch-endpoint', {
			method: 'PATCH',
			data: JSON.stringify({
				key: 'value',
			}),
		});

Encountered the same issue.
PATCH is case sensitive and needs to be uppercase: JakeChampion/fetch#254 (comment)

Facing the same issue with json-server + latest vite version. Tried with axios and worked nicely, and then redaxios crashed about cors.

This is the error thrown
Screenshot 2021-04-16 at 20 18 58

@developit I can open a pull request with the line of "patch" to "PATCH", I've tried it locally and just changing that line works nicely.

@semoal that would be good. Cc me when you do.

@semoal that would be good. Cc me when you do.

Here you have Jason, #66 👍🏻