From 850070ed31771e389bd910f04b0f56a00542808d Mon Sep 17 00:00:00 2001 From: Desyatnikov Grigorii Date: Mon, 27 Dec 2021 22:46:08 +0300 Subject: [PATCH] add request header --- api/ApiMethodFactory.ts | 4 +++- api/TypeHeader.ts | 12 ++++++++++++ api/request.ts | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 api/TypeHeader.ts diff --git a/api/ApiMethodFactory.ts b/api/ApiMethodFactory.ts index 8060283..1ec8fbe 100644 --- a/api/ApiMethodFactory.ts +++ b/api/ApiMethodFactory.ts @@ -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 = null): Promise => { + ) => async (data: Nullable = null, headers: HeadersType = {}): Promise => { const getBody = R.pipe( R.ifElse( R.isNil, @@ -80,6 +81,7 @@ class ApiMethodFactory { method: method, url: endpoint, data: body, + headers: headers, }) } } diff --git a/api/TypeHeader.ts b/api/TypeHeader.ts new file mode 100644 index 0000000..53e1303 --- /dev/null +++ b/api/TypeHeader.ts @@ -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 diff --git a/api/request.ts b/api/request.ts index 8ef08a2..8cacf4d 100644 --- a/api/request.ts +++ b/api/request.ts @@ -7,6 +7,8 @@ const retrieve = async ( hasRetriedAfterAuthentication = false, ): Promise => { try { + console.log(props); + const { data } = await axios(props) return data