mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
Add optional heades for api client push and put
This commit is contained in:
@@ -80,23 +80,24 @@ class ApiClient {
|
||||
return fetch(createUrl(url), applyFetchOptions({})).then(handleFailure);
|
||||
}
|
||||
|
||||
post(url: string, payload?: any, contentType = "application/json") {
|
||||
return this.httpRequestWithJSONBody("POST", url, contentType, payload);
|
||||
post(url: string, payload?: any, contentType = "application/json", additionalHeaders = new Headers()) {
|
||||
return this.httpRequestWithJSONBody("POST", url, contentType, additionalHeaders, payload);
|
||||
}
|
||||
|
||||
postBinary(url: string, fileAppender: (p: FormData) => void) {
|
||||
postBinary(url: string, fileAppender: (p: FormData) => void, additionalHeaders = new Headers()) {
|
||||
const formData = new FormData();
|
||||
fileAppender(formData);
|
||||
|
||||
const options: RequestInit = {
|
||||
method: "POST",
|
||||
body: formData
|
||||
body: formData,
|
||||
headers: additionalHeaders
|
||||
};
|
||||
return this.httpRequestWithBinaryBody(options, url);
|
||||
}
|
||||
|
||||
put(url: string, payload: any, contentType = "application/json") {
|
||||
return this.httpRequestWithJSONBody("PUT", url, contentType, payload);
|
||||
put(url: string, payload: any, contentType = "application/json", additionalHeaders = new Headers()) {
|
||||
return this.httpRequestWithJSONBody("PUT", url, contentType, additionalHeaders, payload);
|
||||
}
|
||||
|
||||
head(url: string) {
|
||||
@@ -115,9 +116,16 @@ class ApiClient {
|
||||
return fetch(createUrl(url), options).then(handleFailure);
|
||||
}
|
||||
|
||||
httpRequestWithJSONBody(method: string, url: string, contentType: string, payload?: any): Promise<Response> {
|
||||
httpRequestWithJSONBody(
|
||||
method: string,
|
||||
url: string,
|
||||
contentType: string,
|
||||
additionalHeaders: Headers,
|
||||
payload?: any
|
||||
): Promise<Response> {
|
||||
const options: RequestInit = {
|
||||
method: method
|
||||
method: method,
|
||||
headers: additionalHeaders
|
||||
};
|
||||
if (payload) {
|
||||
options.body = JSON.stringify(payload);
|
||||
|
||||
Reference in New Issue
Block a user