Skip to content

patch method are not capitalized when api call (http method : patch) #2479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yunyami0605 opened this issue Jul 2, 2022 · 3 comments
Closed

Comments

@yunyami0605
Copy link

I set createApi up like the code below.

And, api call when patch comment.

But, the patch method did not convert from lowercase to upper case automatically. (* I check network tab)

I guess that it is rtk bug.

Because The other http method(get, post, put, delete) was well converted from lower case to upper case automatically.

export const commentApi = createApi({
  reducerPath: "commentApi",
  baseQuery: fetchBaseQuery(commonBaseQueryOption("/comment")),

  refetchOnMountOrArgChange: 0,
  tagTypes: ["comment"],
  endpoints: (builder) => ({

   ...

    // api patch comment content
    patchCommentBoard: builder.mutation<
      number,
      { id?: number; body: { content: string } }
    >({
      query: ({ id, body }) => ({
        url: `/${id}`,
        method: "patch",
        body,
        credentials: "include",
      }),
      transformResponse: (response: IRes<number>) => response.data,
    }),

   ...

  }),
});
@phryneas
Copy link
Member

phryneas commented Jul 2, 2022

This is a "bug" in the fetch specification and you will get the same behaviour with just normal fetch. See JakeChampion/fetch#37

So, this is essentially behaviour baked into your browser.

Best just stick to the HTTP standard and write HTTP methods uppercase from the start.

@phryneas
Copy link
Member

phryneas commented Jul 2, 2022

Also see whatwg/fetch#50 where this is discussed further: bottom line is you should be using uppercased methods from the start, allowing lowercase in the first place is just some legacy compatibility thing and they are not starting to expand that.

@yunyami0605
Copy link
Author

oh! i understand this fetch spec.
Thank you for the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants