@@ -59,7 +59,7 @@ export default class API implements ApiCaller {
59
59
* Prepare/compile the ajax call initialisation.
60
60
*
61
61
* @param {string } url - The endpoint the request goes to.
62
- * @param {'get' | 'post' | 'delete' | 'patch' | 'put' } method - The method the request uses.
62
+ * @param {Method } method - The method the request uses.
63
63
* @param {object= } data - The optional data to send with the request.
64
64
* @param {object= } customHeaders - Custom headers to merge into the request.
65
65
* @param {object= } queryParameters - The query parameters to append to the url
@@ -75,7 +75,8 @@ export default class API implements ApiCaller {
75
75
customHeaders ?: Record < string , MaybeArray < string > > ,
76
76
queryParameters ?: Record < string , unknown >
77
77
) : Promise < { url : string ; requestInit : RequestInit } > {
78
- const initOptions : RequestInit = { method : method . toLowerCase ( ) } ;
78
+ // normalising fetch methods https://fetch.spec.whatwg.org/#concept-method-normalize
79
+ const initOptions : RequestInit = { method : method . toUpperCase ( ) } ;
79
80
const configHeaders = new Headers ( new GlobalConfig ( ) . get ( 'headers' ) ) ;
80
81
queryParameters = queryParameters ?? { } ;
81
82
@@ -100,17 +101,17 @@ export default class API implements ApiCaller {
100
101
101
102
// ensure method is explicitly set if previously
102
103
// removed by initRequest or requestOptions
103
- initOptions . method = initOptions . method ?? 'get ' ;
104
+ initOptions . method = initOptions . method ?? 'GET ' ;
104
105
105
- if ( initOptions . method === 'get ' ) {
106
+ if ( initOptions . method === 'GET ' ) {
106
107
// given if there was any body it was merged in above,
107
108
// we delete it as GET cannot have a body
108
109
delete initOptions . body ;
109
110
}
110
111
111
112
if ( isObjectLiteral ( data ) && Object . keys ( data ) . length || data instanceof FormData ) {
112
113
// if not a GET method
113
- if ( initOptions . method && initOptions . method !== 'get ' ) {
114
+ if ( initOptions . method && initOptions . method !== 'GET ' ) {
114
115
if ( data instanceof FormData ) {
115
116
if ( ! headers . has ( 'Content-Type' ) ) {
116
117
headers . set ( 'Content-Type' , 'multipart/form-data' ) ;
0 commit comments