diff --git a/packages/components/src/api/MakeRequest.ts b/packages/components/src/api/MakeRequest.ts index b9307a7251..44b534625c 100644 --- a/packages/components/src/api/MakeRequest.ts +++ b/packages/components/src/api/MakeRequest.ts @@ -15,21 +15,30 @@ interface RouteSetup { const formatUrl = (endpoint = "") => `${ useSsl ? "https" : "http" }://${ host + endpoint }`; +const METHOD_OMITS_BODY : { [key: string] : boolean } = { + "DELETE": true, + "GET": true, + "OPTIONS": true, + "PATCH": false, + "POST": false, + "PUT": false, +} + const MakeRequest = (routeSetup: RouteSetup) : (urlRouteArgs: UrlRouteArgs, request: Request) => Promise => { return async function(urlRouteArgs: UrlRouteArgs, request: Request) : Promise { const endpoint = routeSetup.routingFunction(urlRouteArgs); const method = routeSetup.method; - const noBodyMethods = ["GET","HEAD", "DELETE", "OPTIONS"].indexOf(method) > -1; - const isGet = method === "GET"; + + const methodOmitsBody = METHOD_OMITS_BODY[method] || false; return fetch(formatUrl(endpoint), { method, headers: { "Accept": "application/json", - ...isGet ? {} : { "Content-Type": "application/json" } + ...methodOmitsBody? {} : { "Content-Type": "application/json" } }, credentials: 'include', - ...noBodyMethod ? {} : { body: JSON.stringify(request) }, + ...methodOmitsBody ? {} : { body: JSON.stringify(request) }, }) .then(res => res.json()) .then(res => {