Skip to content

Commit

Permalink
fix: default request parameters, and use URL for url
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Aug 5, 2024
1 parent 5686858 commit c4e460b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ export const setHeaderToRequest = (request: Request, key: string, value: string)
}

export interface Request {
url: string
url: URL

/**
* @default "GET"
*/
method?: string
method?: "GET" | "POST"

/**
* Body of the request.
* @default undefined
*/
content?: string

/** Headers that should be appended to the request. */
/**
* Headers that should be appended to the request.
* @default {}
*/
headers?: Record<string, string> | Headers

/**
Expand All @@ -80,10 +83,10 @@ export type Fetcher = (req: Request) => Promise<Response>;
* and probably more environments.
*/
export const defaultFetcher = async (req: Request): Promise<Response> => {
const response = await fetch(req.url, {
redirect: req.redirect,
headers: req.headers,
method: req.method,
const response = await fetch(req.url.href, {
redirect: req.redirect ?? "follow",
headers: req.headers ?? {},
method: req.method ?? "GET",
body: req.content
});

Expand Down

0 comments on commit c4e460b

Please sign in to comment.