Skip to content

Commit 34d432b

Browse files
committed
feat: provide TS auto-completion for HTTP methods, but allow any custom string
1 parent 66e825d commit 34d432b

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

example/parameters.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,8 @@ export const jsonBody = {
195195
},
196196
},
197197
};
198+
199+
export const customMethod = {
200+
url: "https://jsonplaceholder.typicode.com/posts",
201+
method: "Cheese",
202+
};

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ type CurlAdditionalOptions = {
5050

5151
type CurlRequest = {
5252
// Query is not official HTTP method, but it's in a RFC and we want to support it. https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-safe-method-w-body
53-
method?: "GET" | "get" | "POST" | "post" | "PUT" | "put" | "PATCH" | "patch" | "DELETE" | "delete" | "HEAD" | "head" | "OPTIONS" | "options" | "CONNECT" | "connect" | "TRACE" | "trace" | "QUERY" | "query",
53+
// All the list of values provide TS auto-completion, but still allow custom methods as string. This is to support non-standard methods like "Cheese"
54+
method?: "GET" | "get" | "POST" | "post" | "PUT" | "put" | "PATCH" | "patch" | "DELETE" | "delete" | "HEAD" | "head" | "OPTIONS" | "options" | "CONNECT" | "connect" | "TRACE" | "trace" | "QUERY" | "query" | (string & {}),
5455
headers?: StringMap,
5556
body?: CurlBody,
5657
url: string,

test/__snapshots__/main.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`customMethod 1`] = `
4+
"curl https://jsonplaceholder.typicode.com/posts \\
5+
undefined"
6+
`;
7+
38
exports[`del1 1`] = `
49
"curl https://jsonplaceholder.typicode.com/posts/1 \\
510
-X DELETE"

0 commit comments

Comments
 (0)