Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.

optional 2nd parameter #10

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,36 +140,36 @@ export default function createClient<T>(defaultOptions?: ClientOptions) {

return {
/** Call a GET endpoint */
async get<U extends PathsWith<'get'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
return coreFetch(url, { ...options, method: 'GET' });
async get<U extends PathsWith<'get'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'GET' });
},
/** Call a PUT endpoint */
async put<U extends PathsWith<'put'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
return coreFetch(url, { ...options, method: 'PUT' });
async put<U extends PathsWith<'put'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'PUT' });
},
/** Call a POST endpoint */
async post<U extends PathsWith<'post'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
return coreFetch(url, { ...options, method: 'POST' });
async post<U extends PathsWith<'post'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'POST' });
},
/** Call a DELETE endpoint */
async del<U extends PathsWith<'delete'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
return coreFetch(url, { ...options, method: 'DELETE' });
async del<U extends PathsWith<'delete'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'DELETE' });
},
/** Call a OPTIONS endpoint */
async options<U extends PathsWith<'options'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
return coreFetch(url, { ...options, method: 'OPTIONS' });
async options<U extends PathsWith<'options'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'OPTIONS' });
},
/** Call a HEAD endpoint */
async head<U extends PathsWith<'head'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
return coreFetch(url, { ...options, method: 'HEAD' });
async head<U extends PathsWith<'head'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'HEAD' });
},
/** Call a PATCH endpoint */
async patch<U extends PathsWith<'patch'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
return coreFetch(url, { ...options, method: 'PATCH' });
async patch<U extends PathsWith<'patch'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'PATCH' });
},
/** Call a TRACE endpoint */
async trace<U extends PathsWith<'trace'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
return coreFetch(url, { ...options, method: 'TRACE' });
async trace<U extends PathsWith<'trace'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'TRACE' });
},
};
}