Skip to content

Commit 541abf4

Browse files
authored
Rename all methods to UPPERCASE (#1243)
1 parent 7aeca8f commit 541abf4

File tree

7 files changed

+107
-102
lines changed

7 files changed

+107
-102
lines changed

.changeset/witty-ears-change.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-fetch": minor
3+
---
4+
5+
⚠️ Breaking: rename all methods to UPPERCASE (`GET()`, `POST()`, etc.)

docs/src/content/docs/openapi-fetch/api.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ createClient<paths>(options);
2121

2222
## Fetch options
2323

24-
The following options apply to all request methods (`.get()`, `.post()`, etc.)
24+
The following options apply to all request methods (`.GET()`, `.POST()`, etc.)
2525

2626
```ts
2727
client.get("/my-url", options);
@@ -43,7 +43,7 @@ client.get("/my-url", options);
4343
This library uses <a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams" target="_blank" rel="noopener noreferrer">URLSearchParams</a> to <a href="https://swagger.io/docs/specification/serialization/" target="_blank" rel="noopener noreferrer">serialize query parameters</a>. For complex query param types (e.g. arrays) you’ll need to provide your own `querySerializer()` method that transforms query params into a URL-safe string:
4444

4545
```ts
46-
const { data, error } = await get("/search", {
46+
const { data, error } = await GET("/search", {
4747
params: {
4848
query: { tags: ["food", "california", "healthy"] },
4949
},
@@ -66,7 +66,7 @@ const { data, error } = await get("/search", {
6666
Similar to [querySerializer](#querySerializer), bodySerializer works for requestBody. You probably only need this when using `multipart/form-data`:
6767

6868
```ts
69-
const { data, error } = await put("/submit", {
69+
const { data, error } = await PUT("/submit", {
7070
body: {
7171
name: "",
7272
query: { version: 2 },

docs/src/content/docs/openapi-fetch/examples.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export const client = computed(authToken, (currentToken) =>
3030
// src/some-other-file.ts
3131
import { client } from "./lib/api";
3232

33-
const { get, post } = client.get();
33+
const { GET, POST } = client.get();
3434

35-
get("/some-authenticated-url", {
35+
GET("/some-authenticated-url", {
3636
/**/
3737
});
3838
```
@@ -63,7 +63,7 @@ export default new Proxy(baseClient, {
6363
// src/some-other-file.ts
6464
import client from "./lib/api";
6565

66-
client.get("/some-authenticated-url", {
66+
client.GET("/some-authenticated-url", {
6767
/**/
6868
});
6969
```
@@ -89,7 +89,7 @@ export default createClient({
8989
// src/some-other-file.ts
9090
import client from "./lib/api";
9191

92-
client.get("/my/endpoint", {
92+
client.GET("/my/endpoint", {
9393
/**/
9494
});
9595
```
@@ -202,7 +202,7 @@ function useUser({ params, body, reactQuery }: UseQueryOptions<paths[typeof GET_
202202
// add any other hook dependencies here
203203
],
204204
queryFn: async ({ signal }) => {
205-
const { data, error } = await client.get(GET_USER, {
205+
const { data, error } = await client.GET(GET_USER, {
206206
params,
207207
// body - isn’t used for GET, but needed for other request types
208208
signal, // allows React Query to cancel request

docs/src/content/docs/openapi-fetch/index.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ The syntax is inspired by popular libraries like react-query or Apollo client, b
1919
import createClient from "openapi-fetch";
2020
import { paths } from "./v1"; // generated from openapi-typescript
2121

22-
const { get, put } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
22+
const { GET, PUT } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
2323

2424
// Type-checked request
25-
await put("/blogposts", {
25+
await PUT("/blogposts", {
2626
body: {
2727
title: "My New Post",
2828
// ❌ Property 'publish_date' is missing in type …
2929
},
3030
});
3131

3232
// Type-checked response
33-
const { data, error } = await get("/blogposts/{post_id}", { params: { path: { post_id: "123" } } });
33+
const { data, error } = await GET("/blogposts/{post_id}", { params: { path: { post_id: "123" } } });
3434
console.log(data.title); // ❌ 'data' is possibly 'undefined'
3535
console.log(error.message); // ❌ 'error' is possibly 'undefined'
3636
console.log(data?.foo); // ❌ Property 'foo' does not exist on type …
@@ -90,16 +90,16 @@ Here’s how you’d fetch GET `/blogposts/{post_id}` and PUT `/blogposts`:
9090
import createClient from "openapi-fetch";
9191
import { paths } from "./v1";
9292

93-
const { get, put } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
93+
const { GET, PUT } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
9494

95-
const { data, error } = await get("/blogposts/{post_id}", {
95+
const { data, error } = await GET("/blogposts/{post_id}", {
9696
params: {
9797
path: { post_id: "my-post" },
9898
query: { version: 2 },
9999
},
100100
});
101101

102-
const { data, error } = await put("/blogposts", {
102+
const { data, error } = await PUT("/blogposts", {
103103
body: {
104104
title: "New Post",
105105
body: "<p>New post body</p>",
@@ -110,7 +110,7 @@ const { data, error } = await put("/blogposts", {
110110

111111
### Pathname
112112

113-
The pathname of `get()`, `put()`, `post()`, etc. **must match your schema literally.** Note in the example, the URL is `/blogposts/{post_id}`. This library will replace all `path` params for you (so they can be typechecked)
113+
The pathname of `GET()`, `PUT()`, `POST()`, etc. **must match your schema literally.** Note in the example, the URL is `/blogposts/{post_id}`. This library will replace all `path` params for you (so they can be typechecked)
114114

115115
> **Tip**
116116
>
@@ -121,9 +121,9 @@ The pathname of `get()`, `put()`, `post()`, etc. **must match your schema litera
121121
122122
### Request
123123

124-
The `get()` request shown needed the `params` object that groups <a href="https://spec.openapis.org/oas/latest.html#parameter-object" target="_blank" rel="noopener noreferrer">parameters by type</a> (`path` or `query`). If a required param is missing, or the wrong type, a type error will be thrown.
124+
The `GET()` request shown needed the `params` object that groups <a href="https://spec.openapis.org/oas/latest.html#parameter-object" target="_blank" rel="noopener noreferrer">parameters by type</a> (`path` or `query`). If a required param is missing, or the wrong type, a type error will be thrown.
125125

126-
The `post()` request required a `body` object that provided all necessary <a href="https://spec.openapis.org/oas/latest.html#request-body-object" target="_blank" rel="noopener noreferrer">requestBody</a> data.
126+
The `POST()` request required a `body` object that provided all necessary <a href="https://spec.openapis.org/oas/latest.html#request-body-object" target="_blank" rel="noopener noreferrer">requestBody</a> data.
127127

128128
### Response
129129

packages/openapi-fetch/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ The syntax is inspired by popular libraries like react-query or Apollo client, b
1414
import createClient from "openapi-fetch";
1515
import { paths } from "./v1"; // (generated from openapi-typescript)
1616

17-
const { get, post } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
17+
const { GET, POST } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
1818

1919
// Type-checked request
20-
await post("/create-post", {
20+
await POST("/create-post", {
2121
body: {
2222
title: "My New Post",
2323
// ❌ Property 'publish_date' is missing in type …
2424
},
2525
});
2626

2727
// Type-checked response
28-
const { data, error } = await get("/blogposts/my-blog-post");
28+
const { data, error } = await GET("/blogposts/my-blog-post");
2929

3030
console.log(data.title); // ❌ 'data' is possibly 'undefined'
3131
console.log(error.message); // ❌ 'error' is possibly 'undefined'
@@ -86,16 +86,16 @@ Here’s how you’d fetch GET `/blogposts/{post_id}` and PUT `/blogposts`:
8686
import createClient from "openapi-fetch";
8787
import { paths } from "./v1";
8888

89-
const { get, put } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
89+
const { GET, PUT } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
9090

91-
const { data, error } = await get("/blogposts/{post_id}", {
91+
const { data, error } = await GET("/blogposts/{post_id}", {
9292
params: {
9393
path: { post_id: "my-post" },
9494
query: { version: 2 },
9595
},
9696
});
9797

98-
const { data, error } = await put("/blogposts", {
98+
const { data, error } = await PUT("/blogposts", {
9999
body: {
100100
title: "New Post",
101101
body: "<p>New post body</p>",

0 commit comments

Comments
 (0)