add request header

This commit is contained in:
Grigorii Desyatnikov 2021-12-27 22:46:08 +03:00
parent 0760a53364
commit 850070ed31
3 changed files with 17 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import * as R from 'ramda'
import { sprintf } from 'sprintf-js'
import request from './request'
import HttpMethod from './HttpMethod'
import HeadersType from './TypeHeader'
class ApiMethodFactory {
private readonly apiPrefix: string
@ -63,7 +64,7 @@ class ApiMethodFactory {
path: pathKeys = [],
query: queryKeys = [],
}: { path?: string[], query?: string[] } = {},
) => async (data: Nullable<T> = null): Promise<R> => {
) => async (data: Nullable<T> = null, headers: HeadersType = {}): Promise<R> => {
const getBody = R.pipe(
R.ifElse(
R.isNil,
@ -80,6 +81,7 @@ class ApiMethodFactory {
method: method,
url: endpoint,
data: body,
headers: headers,
})
}
}

12
api/TypeHeader.ts Normal file
View File

@ -0,0 +1,12 @@
interface HeadersType {
'Content-Type'?: ContentType
Accept?: string
}
export enum ContentType {
// MULTIPART = 'multipart/form-data; boundary=boundary',
MULTIPART = 'multipart/form-data',
JSON = 'application/json',
}
export default HeadersType

View File

@ -7,6 +7,8 @@ const retrieve = async (
hasRetriedAfterAuthentication = false,
): Promise<any> => {
try {
console.log(props);
const { data } = await axios(props)
return data