diff --git a/packages/fetch/src/core.ts b/packages/fetch/src/core.ts index 8dcd139b..26ba4b7f 100644 --- a/packages/fetch/src/core.ts +++ b/packages/fetch/src/core.ts @@ -41,12 +41,12 @@ export function processOptions_(options: FetchOptions): Required { options.removeDuplicate = cacheSupported ? 'until_load' : 'always'; } - if (options.url.lastIndexOf('?') === -1 && options.queryParameters != null) { - const queryParameters = options.queryParameters; + if (options.url.lastIndexOf('?') === -1 && options.queryParams != null) { + const queryParams = options.queryParams; // prettier-ignore const queryArray = Object - .keys(queryParameters) - .map((key) => `${key}=${String(queryParameters[key])}`); + .keys(queryParams) + .map((key) => `${key}=${String(queryParams[key])}`); if (queryArray.length > 0) { options.url += '?' + queryArray.join('&'); diff --git a/packages/fetch/src/main.test.js b/packages/fetch/src/main.test.js index fb8a723e..43594bab 100644 --- a/packages/fetch/src/main.test.js +++ b/packages/fetch/src/main.test.js @@ -7,7 +7,7 @@ describe('fetch with search params', () => { */ const options = { url: 'http://httpbin.org/get', - queryParameters: { + queryParams: { a: 2, }, cacheStrategy: 'network_only', diff --git a/packages/fetch/src/type.ts b/packages/fetch/src/type.ts index be51cfa5..4ff25eb1 100644 --- a/packages/fetch/src/type.ts +++ b/packages/fetch/src/type.ts @@ -3,13 +3,13 @@ import type {Dictionary, Json, JsonObject} from '@alwatr/type-helper'; /** * Represents the available HTTP methods. */ -export type Methods = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'TRACE' | 'OPTIONS' | 'PATCH'; +export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE'; /** * Represents a dictionary of query parameters. * The keys are strings and the values can be strings, numbers, or booleans. */ -export type QueryParameters = Dictionary; +export type QueryParams = Dictionary; /** * Represents the cache strategy for fetching data. @@ -46,7 +46,7 @@ export interface FetchOptions extends RequestInit { * * @default 'GET' */ - method?: Methods; + method?: HttpMethod; /** * A Headers object to set the request's headers. @@ -121,7 +121,7 @@ export interface FetchOptions extends RequestInit { /** * URL query parameters as a JavaScript object. */ - queryParameters?: QueryParameters; + queryParams?: QueryParams; /** * Add token to the Authentication bearer header.