({ url, params, data, noAuth }: PostArgs, abortController?: AbortController)
| 100 | } |
| 101 | |
| 102 | export async function post({ url, params, data, noAuth }: PostArgs, abortController?: AbortController) { |
| 103 | const apiUrl = buildUrl({ url, params }); |
| 104 | const method = "POST"; |
| 105 | |
| 106 | let headers: Record<string, string> = {}; |
| 107 | if (!noAuth) { |
| 108 | headers = { |
| 109 | ...buildAuthHeader(), |
| 110 | }; |
| 111 | } |
| 112 | |
| 113 | let body: string | FormData | undefined; |
| 114 | // Check if the data is an instance of FormData |
| 115 | // If data is FormData, let the browser set the Content-Type header |
| 116 | if (data instanceof FormData) { |
| 117 | body = data; |
| 118 | } else { |
| 119 | // If data is JSON, set the Content-Type header to 'application/json' |
| 120 | headers = { |
| 121 | ...headers, |
| 122 | [contentTypeHeader]: "application/json", |
| 123 | }; |
| 124 | body = buildBody(data); |
| 125 | } |
| 126 | |
| 127 | const signal = abortController?.signal; |
| 128 | const response = await fetch(apiUrl, { method, headers, body, signal }); |
| 129 | return processResponse(response); |
| 130 | } |
| 131 | |
| 132 | interface PutArgs { |
| 133 | url: string; |
nothing calls this directly
no test coverage detected