@@ -12,23 +12,23 @@ exports.makeApiRequest = (config, endpoint, userParameters) => {
12
12
if ( userParameters !== undefined ) {
13
13
const { requestType, parameters } = endpoint
14
14
15
+ // All methods may have path parameters
16
+ const pathParams = Object . keys ( userParameters ) . filter (
17
+ ( key ) => parameters [ key ] . path
18
+ )
19
+
20
+ if ( pathParams . length ) {
21
+ pathParams . forEach ( ( param ) => {
22
+ // Ex. '/bare-metals/{baremetal-id}/ipv4' becomes '/bare-metals/123456/ipv4'
23
+ fetchUrl = fetchUrl . replace ( `{${ param } }` , userParameters [ param ] )
24
+ } )
25
+ }
26
+
15
27
if ( requestType === 'POST' ) {
16
28
// POST requests will just send all data as JSON to the endpoint
17
29
options . body = JSON . stringify ( userParameters )
18
30
options . headers [ 'Content-Type' ] = 'application/json'
19
31
} else {
20
- // GET, DELETE, PATCH, and PUT may have path parameters
21
- const pathParams = Object . keys ( userParameters ) . filter (
22
- ( key ) => parameters [ key ] . path
23
- )
24
-
25
- if ( pathParams . length ) {
26
- pathParams . forEach ( ( param ) => {
27
- // Ex. '/bare-metals/{baremetal-id}/ipv4' becomes '/bare-metals/123456/ipv4'
28
- fetchUrl = fetchUrl . replace ( `{${ param } }` , userParameters [ param ] )
29
- } )
30
- }
31
-
32
32
if ( requestType === 'GET' || requestType === 'DELETE' ) {
33
33
// GET and DELETE requests may have path parameters as well as query parameters
34
34
const queryParams = Object . keys ( userParameters )
0 commit comments