@@ -176,39 +176,15 @@ export default function createClient(clientOptions) {
176
176
return { error, response } ;
177
177
}
178
178
179
- return {
180
- /** Call a GET endpoint */
181
- async GET ( url , init ) {
182
- return coreFetch ( url , { ...init , method : "GET" } ) ;
183
- } ,
184
- /** Call a PUT endpoint */
185
- async PUT ( url , init ) {
186
- return coreFetch ( url , { ...init , method : "PUT" } ) ;
187
- } ,
188
- /** Call a POST endpoint */
189
- async POST ( url , init ) {
190
- return coreFetch ( url , { ...init , method : "POST" } ) ;
191
- } ,
192
- /** Call a DELETE endpoint */
193
- async DELETE ( url , init ) {
194
- return coreFetch ( url , { ...init , method : "DELETE" } ) ;
195
- } ,
196
- /** Call a OPTIONS endpoint */
197
- async OPTIONS ( url , init ) {
198
- return coreFetch ( url , { ...init , method : "OPTIONS" } ) ;
199
- } ,
200
- /** Call a HEAD endpoint */
201
- async HEAD ( url , init ) {
202
- return coreFetch ( url , { ...init , method : "HEAD" } ) ;
203
- } ,
204
- /** Call a PATCH endpoint */
205
- async PATCH ( url , init ) {
206
- return coreFetch ( url , { ...init , method : "PATCH" } ) ;
207
- } ,
208
- /** Call a TRACE endpoint */
209
- async TRACE ( url , init ) {
210
- return coreFetch ( url , { ...init , method : "TRACE" } ) ;
211
- } ,
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
+ ) ;
184
+
185
+ const coreClient = {
186
+ ...methodMembers ,
187
+
212
188
/** Register middleware */
213
189
use ( ...middleware ) {
214
190
for ( const m of middleware ) {
@@ -231,6 +207,19 @@ export default function createClient(clientOptions) {
231
207
}
232
208
} ,
233
209
} ;
210
+
211
+ const handler = {
212
+ get : ( coreClient , property ) => {
213
+ if ( property in coreClient ) {
214
+ return coreClient [ property ] ;
215
+ }
216
+
217
+ // Assume the property is an URL.
218
+ return Object . fromEntries ( methods . map ( ( method ) => [ method , ( init ) => coreFetch ( property , { ...init , method } ) ] ) ) ;
219
+ } ,
220
+ } ;
221
+
222
+ return new Proxy ( coreClient , handler ) ;
234
223
}
235
224
236
225
// utils
0 commit comments