summaryrefslogtreecommitdiff
path: root/src/apiSlice.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/apiSlice.ts')
-rw-r--r--src/apiSlice.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/apiSlice.ts b/src/apiSlice.ts
new file mode 100644
index 0000000..6d779ed
--- /dev/null
+++ b/src/apiSlice.ts
@@ -0,0 +1,26 @@
+import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
+
+export const apiSlice = createApi({
+ reducerPath: 'api',
+ baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:3000' }),
+ tagTypes: ['Guests'],
+ endpoints: builder => ({
+ getGuests: builder.query({
+ query: () => '/guests',
+ providesTags: ['Guests']
+ }),
+ updateGuest: builder.mutation({
+ query: guest => ({
+ url: `/guests/${guest.id}`,
+ method: 'PATCH',
+ body: guest,
+ providesTags: ['Guests']
+ })
+ })
+ })
+});
+
+export const {
+ useGetGuestsQuery,
+ useUpdateGuestMutation
+} = apiSlice;