Created
February 22, 2021 20:04
-
-
Save AllGistsEqual/eff869407e1d6d516dcc0edd6b1ddec7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// File: src/redux/ducks/api.ts | |
import { Middleware, Action } from 'redux' | |
import { createAction } from '@reduxjs/toolkit' | |
const API_HOST = 'http://localhost:3031' | |
export type SuccessAction<T> = (data: T) => Action | |
export type ErrorAction = (message: string) => Action | |
export type ApiBaseRequest = { | |
url: string | |
headers?: Record<string, string> | |
} | |
export type ApiGetRequest = ApiBaseRequest & { | |
method: 'GET' | |
} | |
export type ApiPostRequest = ApiBaseRequest & { | |
method: 'POST' | |
data: Record<string, unknown> | |
} | |
export type ApiPutRequest = ApiBaseRequest & { | |
method: 'PUT' | |
data: Record<string, unknown> | |
} | |
export type ApiDeleteRequest = ApiBaseRequest & { | |
method: 'DELETE' | |
} | |
export type ApiRequest = ApiGetRequest | ApiPostRequest | ApiPutRequest | ApiDeleteRequest | |
export type ApiRequestPayload<T = never> = ApiRequest & { | |
onSuccess: SuccessAction<T> | |
onError: ErrorAction | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment