From 3707d11fc06c4a1d5134ffee626166d813c23e0a Mon Sep 17 00:00:00 2001 From: Ivn Nv Date: Sun, 8 Feb 2026 12:10:47 -0500 Subject: [PATCH] Add PATCH method support to the CLI api command The CapRover server now supports PATCH for partial app definition updates (caprover/caprover#2372), but the CLI only allows GET and POST. This adds PATCH as a valid method for the `caprover api` command, enabling safe partial updates like scaling without wiping other fields. Changes: - Constants.ts: add 'PATCH' to API_METHODS - HttpClient.ts: add patchReq() and PATCH dispatch in fetchInternal() - ApiManager.ts: widen callApi() type to accept 'PATCH' --- src/api/ApiManager.ts | 2 +- src/api/HttpClient.ts | 21 +++++++++++++++++++-- src/utils/Constants.ts | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/api/ApiManager.ts b/src/api/ApiManager.ts index 103b2c9..73a76c8 100644 --- a/src/api/ApiManager.ts +++ b/src/api/ApiManager.ts @@ -38,7 +38,7 @@ export default class ApiManager { callApi( path: string, - method: 'GET' | 'POST' /*| 'POST_DATA' Not used */, + method: 'GET' | 'POST' | 'PATCH' /*| 'POST_DATA' Not used */, data: any ) { const http = this.http diff --git a/src/api/HttpClient.ts b/src/api/HttpClient.ts index e4e960b..19e28ea 100644 --- a/src/api/HttpClient.ts +++ b/src/api/HttpClient.ts @@ -11,6 +11,7 @@ export default class HttpClient { readonly GET = 'GET' readonly POST = 'POST' readonly POST_DATA = 'POST_DATA' + readonly PATCH = 'PATCH' isDestroyed = false constructor( @@ -47,7 +48,7 @@ export default class HttpClient { } fetch( - method: 'GET' | 'POST' | 'POST_DATA', + method: 'GET' | 'POST' | 'POST_DATA' | 'PATCH', endpoint: string, variables: any ) { @@ -123,7 +124,7 @@ export default class HttpClient { } fetchInternal( - method: 'GET' | 'POST' | 'POST_DATA', + method: 'GET' | 'POST' | 'POST_DATA' | 'PATCH', endpoint: string, variables: any ) { @@ -135,6 +136,10 @@ export default class HttpClient { return this.postReq(endpoint, variables, method) } + if (method === this.PATCH) { + return this.patchReq(endpoint, variables) + } + throw new Error('Unknown method: ' + method) } @@ -175,4 +180,16 @@ export default class HttpClient { return data }) } + + patchReq(endpoint: string, variables: any) { + const self = this + + return Request.patch(this.baseUrl + endpoint, { + headers: self.createHeaders(), + body: variables, + json: true + }).then(function (data) { + return data + }) + } } diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 2cccc04..b54b448 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -6,7 +6,7 @@ const CANCEL_STRING = '-- CANCEL --' const SETUP_PORT = 3000 const MIN_CHARS_FOR_PASSWORD = 8 const BASE_API_PATH = '/api/v2' -const API_METHODS = ['GET', 'POST'] +const API_METHODS = ['GET', 'POST', 'PATCH'] export default { ADMIN_DOMAIN,