Update api.tsx

Allow headers
This commit is contained in:
Justin Edmund 2020-09-26 10:51:30 -07:00
parent 2b78605ac9
commit b2e62ae89e

View file

@ -6,7 +6,7 @@ interface Entity {
type CollectionEndpoint = ({ query }: { query: AxiosRequestConfig }) => Promise<AxiosResponse<any>>
type IdEndpoint = ({ id }: { id: string }) => Promise<AxiosResponse<any>>
type PostEndpoint = (object: {}) => Promise<AxiosResponse<any>>
type PostEndpoint = (object: {}, headers?: {}) => Promise<AxiosResponse<any>>
interface EndpointMap {
getAll: CollectionEndpoint
@ -39,8 +39,8 @@ class Api {
return {
getAll: ({ query }: { query: AxiosRequestConfig }) => axios.get(resourceUrl, { params: { query }}),
getOne: ({ id }: { id: string }) => axios.get(`${resourceUrl}/${id}`),
create: (object: {}) => axios.post(resourceUrl, object),
update: (object: {}) => axios.put(resourceUrl, object),
create: (object: {}, headers?: {}) => axios.post(resourceUrl, object, headers),
update: (object: {}, headers?: {}) => axios.put(resourceUrl, object, headers),
destroy: ({ id }: { id: string }) => axios.delete(`${resourceUrl}/${id}`)
} as EndpointMap
}