Skip to content

Commit ee62fd7

Browse files
committed
Cleanup method handling
1 parent ce8ace8 commit ee62fd7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packages/openapi-fetch/src/index.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,15 @@ export default function createClient(clientOptions) {
176176
return { error, response };
177177
}
178178

179-
// Poor-man's set.
180-
const methods = { GET: 0, PUT: 0, POST: 0, DELETE: 0, OPTIONS: 0, HEAD: 0, PATCH: 0, TRACE: 0 };
179+
const methods = ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
180+
181+
const methodMembers = Object.fromEntries(
182+
methods.map((method) => [method, (url, init) => coreFetch(url, { ...init, method })]),
183+
);
181184

182185
const coreClient = {
186+
...methodMembers,
187+
183188
/** Register middleware */
184189
use(...middleware) {
185190
for (const m of middleware) {
@@ -209,13 +214,9 @@ export default function createClient(clientOptions) {
209214
return coreClient[property];
210215
}
211216

212-
if (property in methods) {
213-
return (url, init) => coreFetch(url, { ...init, method: property });
214-
}
215-
216-
// Assume the property is a URL.
217+
// Assume the property is an URL.
217218
return Object.fromEntries(
218-
Object.keys(methods).map((method) => [method, (init) => coreFetch(property, { ...init, method })]),
219+
methods.map((method) => [method, (init) => coreFetch(property, { ...init, method })]),
219220
);
220221
},
221222
};

0 commit comments

Comments
 (0)