Skip to content

Commit ead8694

Browse files
committed
* change get/update singular post example
endpoints from 'posts/:id' -> 'post/:id'
1 parent 6cf605f commit ead8694

14 files changed

+43
-43
lines changed

docs/rtk-query/api/createApi.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,17 @@ const api = createApi({
506506
}),
507507
endpoints: (build) => ({
508508
getPost: build.query<Post, number>({
509-
query: (id) => `posts/${id}`,
509+
query: (id) => `post/${id}`,
510510
async onQueryStarted(id, { dispatch, queryFulfilled }) {
511511
// `onStart` side-effect
512-
dispatch(messageCreated('Fetching posts...'))
512+
dispatch(messageCreated('Fetching post...'))
513513
try {
514514
const { data } = await queryFulfilled
515515
// `onSuccess` side-effect
516-
dispatch(messageCreated('Posts received!'))
516+
dispatch(messageCreated('Post received!'))
517517
} catch (err) {
518518
// `onError` side-effect
519-
dispatch(messageCreated('Error fetching posts!'))
519+
dispatch(messageCreated('Error fetching post!'))
520520
}
521521
},
522522
}),

docs/rtk-query/usage-with-typescript.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ const api = createApi({
216216
getPost: build.query<Post, number>({
217217
// inferred as `number` from the `QueryArg` type
218218
// v
219-
query: (id) => `posts/${id}`,
219+
query: (id) => `post/${id}`,
220220
// An explicit type must be provided to the raw result that the query returns
221221
// when using `transformResponse`
222222
// v
@@ -452,7 +452,7 @@ export const api = createApi({
452452
// Query argument is required to be `number`, and can't be `undefined`
453453
// V
454454
getPost: build.query<Post, number>({
455-
query: (id) => `posts/${id}`,
455+
query: (id) => `post/${id}`,
456456
}),
457457
}),
458458
})

docs/rtk-query/usage/automated-refetching.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ const api = createApi({
8787
}),
8888
addPost: build.mutation<Post, Omit<Post, 'id'>>({
8989
query: (body) => ({
90-
url: 'posts',
90+
url: 'post',
9191
method: 'POST',
9292
body,
9393
}),
9494
}),
9595
editPost: build.mutation<Post, Partial<Post> & Pick<Post, 'id'>>({
9696
query: (body) => ({
97-
url: `posts/${body.id}`,
97+
url: `post/${body.id}`,
9898
method: 'POST',
9999
body,
100100
}),
@@ -160,7 +160,7 @@ const api = createApi({
160160
}),
161161
editPost: build.mutation<Post, Partial<Post> & Pick<Post, 'id'>>({
162162
query: (body) => ({
163-
url: `posts/${body.id}`,
163+
url: `post/${body.id}`,
164164
method: 'POST',
165165
body,
166166
}),
@@ -210,14 +210,14 @@ const api = createApi({
210210
}),
211211
addPost: build.mutation<Post, Omit<Post, 'id'>>({
212212
query: (body) => ({
213-
url: 'posts',
213+
url: 'post',
214214
method: 'POST',
215215
body,
216216
}),
217217
}),
218218
editPost: build.mutation<Post, Partial<Post> & Pick<Post, 'id'>>({
219219
query: (body) => ({
220-
url: `posts/${body.id}`,
220+
url: `post/${body.id}`,
221221
method: 'POST',
222222
body,
223223
}),
@@ -275,7 +275,7 @@ const api = createApi({
275275
}),
276276
addPost: build.mutation<Post, Omit<Post, 'id'>>({
277277
query: (body) => ({
278-
url: 'posts',
278+
url: 'post',
279279
method: 'POST',
280280
body,
281281
}),
@@ -285,7 +285,7 @@ const api = createApi({
285285
}),
286286
editPost: build.mutation<Post, Partial<Post> & Pick<Post, 'id'>>({
287287
query: (body) => ({
288-
url: `posts/${body.id}`,
288+
url: `post/${body.id}`,
289289
method: 'POST',
290290
body,
291291
}),
@@ -355,15 +355,15 @@ const api = createApi({
355355
}),
356356
addPost: build.mutation<Post, Omit<Post, 'id'>>({
357357
query: (body) => ({
358-
url: 'posts',
358+
url: 'post',
359359
method: 'POST',
360360
body,
361361
}),
362362
invalidatesTags: ['Post'],
363363
}),
364364
editPost: build.mutation<Post, Partial<Post> & Pick<Post, 'id'>>({
365365
query: (body) => ({
366-
url: `posts/${body.id}`,
366+
url: `post/${body.id}`,
367367
method: 'POST',
368368
body,
369369
}),
@@ -647,14 +647,14 @@ export const api = createApi({
647647
}),
648648
addPost: build.mutation<Post, Partial<Post>>({
649649
query: (body) => ({
650-
url: `posts`,
650+
url: `post`,
651651
method: 'POST',
652652
body,
653653
}),
654654
invalidatesTags: ['Posts'],
655655
}),
656656
getPost: build.query<Post, number>({
657-
query: (id) => `posts/${id}`,
657+
query: (id) => `post/${id}`,
658658
providesTags: (result, error, id) => [{ type: 'Posts', id }],
659659
}),
660660
}),
@@ -720,15 +720,15 @@ export const api = createApi({
720720
addPost: build.mutation<Post, Partial<Post>>({
721721
query(body) {
722722
return {
723-
url: `posts`,
723+
url: `post`,
724724
method: 'POST',
725725
body,
726726
}
727727
},
728728
invalidatesTags: [{ type: 'Posts', id: 'LIST' }],
729729
}),
730730
getPost: build.query<Post, number>({
731-
query: (id) => `posts/${id}`,
731+
query: (id) => `post/${id}`,
732732
providesTags: (result, error, id) => [{ type: 'Posts', id }],
733733
}),
734734
}),
@@ -797,7 +797,7 @@ const api = createApi({
797797
tagTypes: ['Post', 'UNAUTHORIZED', 'UNKNOWN_ERROR'],
798798
endpoints: (build) => ({
799799
postById: build.query<Post, number>({
800-
query: (id) => `posts/${id}`,
800+
query: (id) => `post/${id}`,
801801
providesTags: (result, error, id) =>
802802
result
803803
? [{ type: 'Post', id }]

docs/rtk-query/usage/customizing-queries.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ export const api = createApi({
427427
query: () => ({ url: 'posts' }),
428428
}),
429429
getPost: build.query<PostsResponse, string>({
430-
query: (id) => ({ url: `posts/${id}` }),
430+
query: (id) => ({ url: `post/${id}` }),
431431
extraOptions: { maxRetries: 8 }, // You can override the retry behavior on each endpoint
432432
}),
433433
}),

docs/rtk-query/usage/mutations.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const api = createApi({
3636
// highlight-start
3737
// note: an optional `queryFn` may be used in place of `query`
3838
query: ({ id, ...patch }) => ({
39-
url: `posts/${id}`,
39+
url: `post/${id}`,
4040
method: 'PATCH',
4141
body: patch,
4242
}),
@@ -182,7 +182,7 @@ export const postApi = createApi({
182182
addPost: build.mutation<Post, Partial<Post>>({
183183
query(body) {
184184
return {
185-
url: `posts`,
185+
url: `poss`,
186186
method: 'POST',
187187
body,
188188
}
@@ -192,14 +192,14 @@ export const postApi = createApi({
192192
invalidatesTags: [{ type: 'Posts', id: 'LIST' }],
193193
}),
194194
getPost: build.query<Post, number>({
195-
query: (id) => `posts/${id}`,
195+
query: (id) => `post/${id}`,
196196
providesTags: (result, error, id) => [{ type: 'Posts', id }],
197197
}),
198198
updatePost: build.mutation<Post, Partial<Post>>({
199199
query(data) {
200200
const { id, ...body } = data
201201
return {
202-
url: `posts/${id}`,
202+
url: `post/${id}`,
203203
method: 'PUT',
204204
body,
205205
}
@@ -211,7 +211,7 @@ export const postApi = createApi({
211211
deletePost: build.mutation<{ success: boolean; id: number }, number>({
212212
query(id) {
213213
return {
214-
url: `posts/${id}`,
214+
url: `post/${id}`,
215215
method: 'DELETE',
216216
}
217217
},

docs/rtk-query/usage/optimistic-updates.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ const api = createApi({
3535
tagTypes: ['Post'],
3636
endpoints: (build) => ({
3737
getPost: build.query<Post, number>({
38-
query: (id) => `posts/${id}`,
38+
query: (id) => `post/${id}`,
3939
providesTags: ['Post'],
4040
}),
4141
updatePost: build.mutation<void, Pick<Post, 'id'> & Partial<Post>>({
4242
query: ({ id, ...patch }) => ({
43-
url: `posts/${id}`,
43+
url: `post/${id}`,
4444
method: 'PATCH',
4545
body: patch,
4646
}),

docs/rtk-query/usage/queries.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const api = createApi({
3838
getPost: build.query<Post, number>({
3939
// highlight-start
4040
// note: an optional `queryFn` may be used in place of `query`
41-
query: (id) => ({ url: `posts/${id}` }),
41+
query: (id) => ({ url: `post/${id}` }),
4242
// Pick out data and prevent nested properties in a hook or selector
4343
transformResponse: (response: { data: Post }) => response.data,
4444
providesTags: (result, error, id) => [{ type: 'Post', id }],

src/query/core/buildMiddleware/queryLifecycle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ declare module '../../endpointDefinitions' {
9393
* }),
9494
* endpoints: (build) => ({
9595
* getPost: build.query<Post, number>({
96-
* query: (id) => `posts/${id}`,
96+
* query: (id) => `post/${id}`,
9797
* async onQueryStarted(id, { dispatch, queryFulfilled }) {
9898
* // `onStart` side-effect
9999
* dispatch(messageCreated('Fetching posts...'))
@@ -145,12 +145,12 @@ declare module '../../endpointDefinitions' {
145145
* tagTypes: ['Post'],
146146
* endpoints: (build) => ({
147147
* getPost: build.query<Post, number>({
148-
* query: (id) => `posts/${id}`,
148+
* query: (id) => `post/${id}`,
149149
* providesTags: ['Post'],
150150
* }),
151151
* updatePost: build.mutation<void, Pick<Post, 'id'> & Partial<Post>>({
152152
* query: ({ id, ...patch }) => ({
153-
* url: `posts/${id}`,
153+
* url: `post/${id}`,
154154
* method: 'PATCH',
155155
* body: patch,
156156
* }),

src/query/endpointDefinitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export type EndpointBuilder<
368368
* baseQuery,
369369
* endpoints: (build) => ({
370370
* getPost: build.query({
371-
* query: (id) => ({ url: `posts/${id}` }),
371+
* query: (id) => ({ url: `post/${id}` }),
372372
* // Pick out data and prevent nested properties in a hook or selector
373373
* transformResponse: (response) => response.data,
374374
* // `result` is the server response
@@ -398,7 +398,7 @@ export type EndpointBuilder<
398398
* baseQuery,
399399
* endpoints: (build) => ({
400400
* updatePost: build.mutation({
401-
* query: ({ id, ...patch }) => ({ url: `posts/${id}`, method: 'PATCH', body: patch }),
401+
* query: ({ id, ...patch }) => ({ url: `post/${id}`, method: 'PATCH', body: patch }),
402402
* // Pick out data and prevent nested properties in a hook or selector
403403
* transformResponse: (response) => response.data,
404404
* // `result` is the server response

src/query/retry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const retryWithBackoff: BaseQueryEnhancer<
9999
* query: () => ({ url: 'posts' }),
100100
* }),
101101
* getPost: build.query<PostsResponse, string>({
102-
* query: (id) => ({ url: `posts/${id}` }),
102+
* query: (id) => ({ url: `post/${id}` }),
103103
* extraOptions: { maxRetries: 8 }, // You can override the retry behavior on each endpoint
104104
* }),
105105
* }),

0 commit comments

Comments
 (0)