Skip to content

Commit 5fc8111

Browse files
authored
Change .get('/post') as it’s confusing (#1175)
* Change .get('/post') as it’s confusing Changed /post to /blogpost * Update docs deps
1 parent 5ca0255 commit 5fc8111

File tree

19 files changed

+6788
-4528
lines changed

19 files changed

+6788
-4528
lines changed

docs/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
"update-contributors": "node scripts/update-contributors.js"
1010
},
1111
"dependencies": {
12-
"@algolia/client-search": "^4.17.0",
13-
"@astrojs/preact": "^2.2.0",
14-
"@astrojs/react": "^2.2.0",
15-
"@docsearch/css": "^3.3.5",
16-
"@docsearch/react": "^3.3.5",
17-
"@types/react": "^18.2.6",
18-
"@types/react-dom": "^18.2.4",
19-
"astro": "^2.5.4",
20-
"preact": "^10.15.0",
12+
"@algolia/client-search": "^4.17.2",
13+
"@astrojs/preact": "^2.2.1",
14+
"@astrojs/react": "^2.2.1",
15+
"@docsearch/css": "^3.5.1",
16+
"@docsearch/react": "^3.5.1",
17+
"@types/react": "^18.2.12",
18+
"@types/react-dom": "^18.2.5",
19+
"astro": "^2.6.4",
20+
"preact": "^10.15.1",
2121
"react": "^18.2.0",
2222
"react-dom": "^18.2.0",
23-
"sass": "^1.62.1"
23+
"sass": "^1.63.4"
2424
},
2525
"devDependencies": {
26-
"@astrojs/sitemap": "^1.3.1",
27-
"@types/node": "^20.2.3",
26+
"@astrojs/sitemap": "^1.3.3",
27+
"@types/node": "^20.3.1",
2828
"html-escaper": "^3.0.3",
2929
"typescript": "^5.1.3"
3030
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { paths } from "./v1"; // generated from openapi-typescript
4747

4848
const { get, post } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
4949

50-
const { data, error } = await get("/post/{post_id}", {
50+
const { data, error } = await get("/blogposts/{post_id}", {
5151
params: {
5252
path: { post_id: "my-post" },
5353
query: { version: 2 },

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import { paths } from "./v1"; // generated from openapi-typescript
2222
const { get, post } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
2323

2424
// Type-checked request
25-
await post("/create-post", {
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("/post/my-blog-post");
33+
const { data, error } = await get("/blogposts/my-blog-post");
3434

3535
console.log(data.title); // ❌ 'data' is possibly 'undefined'
3636
console.log(error.message); // ❌ 'error' is possibly 'undefined'
@@ -85,24 +85,22 @@ Using **openapi-fetch** is as easy as reading your schema! For example, given th
8585

8686
![OpenAPI schema example](/assets/openapi-schema.png)
8787

88-
Here’s how you’d fetch `/post/{post_id}` and `/create-post`:
88+
Here’s how you’d fetch GET `/blogposts/{post_id}` and POST `/blogposts`:
8989

9090
```ts
9191
import createClient from "openapi-fetch";
9292
import { paths } from "./v1";
9393

9494
const { get, post } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
9595

96-
// GET /post/{post_id}
97-
const { data, error } = await get("/post/{post_id}", {
96+
const { data, error } = await get("/blogposts/{post_id}", {
9897
params: {
9998
path: { post_id: "my-post" },
10099
query: { version: 2 },
101100
},
102101
});
103102

104-
// POST /create-post
105-
const { data, error } = await post("/create-post", {
103+
const { data, error } = await post("/blogposts", {
106104
body: {
107105
title: "New Post",
108106
body: "<p>New post body</p>",
@@ -113,13 +111,13 @@ const { data, error } = await post("/create-post", {
113111

114112
### Pathname
115113

116-
The pathname of `get()`, `put()`, `post()`, etc. **must match your schema literally.** Note in the example, the URL is `/post/{post_id}`. This library will replace all `path` params for you (so they can be typechecked)
114+
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)
117115

118116
> **Tip**
119117
>
120118
> openapi-fetch infers types from the URL. Prefer static string values over dynamic runtime values, e.g.:
121119
>
122-
> - ✅ `"/post/{post_id}"`
120+
> - ✅ `"/blogposts/{post_id}"`
123121
> - ❌ `[...pathParts].join("/") + "{post_id}"`
124122
125123
### Request

packages/openapi-fetch/README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ await post("/create-post", {
2525
});
2626

2727
// Type-checked response
28-
const { data, error } = await get("/post/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'
@@ -80,24 +80,22 @@ Using **openapi-fetch** is as easy as reading your schema! For example, given th
8080

8181
![OpenAPI schema example](../../../docs/public/assets/openapi-schema.png)
8282

83-
Here’s how you’d fetch `/post/{post_id}` and `/create-post`:
83+
Here’s how you’d fetch GET `/blogpost/{post_id}` and POST `/blogposts`:
8484

8585
```ts
8686
import createClient from "openapi-fetch";
8787
import { paths } from "./v1";
8888

8989
const { get, post } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });
9090

91-
// GET /post/{post_id}
92-
const { data, error } = await get("/post/{post_id}", {
91+
const { data, error } = await get("/blogposts/{post_id}", {
9392
params: {
9493
path: { post_id: "my-post" },
9594
query: { version: 2 },
9695
},
9796
});
9897

99-
// POST /create-post
100-
const { data, error } = await post("/create-post", {
98+
const { data, error } = await post("/blogposts", {
10199
body: {
102100
title: "New Post",
103101
body: "<p>New post body</p>",
@@ -108,13 +106,13 @@ const { data, error } = await post("/create-post", {
108106

109107
### Pathname
110108

111-
The pathname of `get()`, `put()`, `post()`, etc. **must match your schema literally.** Note in the example, the URL is `/post/{post_id}`. This library will replace all `path` params for you (so they can be typechecked)
109+
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)
112110

113111
> **Tip**
114112
>
115113
> openapi-fetch infers types from the URL. Prefer static string values over dynamic runtime values, e.g.:
116114
>
117-
> - ✅ `"/post/{post_id}"`
115+
> - ✅ `"/blogposts/{post_id}"`
118116
> - ❌ `[...pathParts].join("/") + "{post_id}"`
119117
120118
### Request

0 commit comments

Comments
 (0)