Skip to content

Commit b18a939

Browse files
committed
feat[typing-app]: バックエンドAPIを呼ぶクライアントを作成
1 parent 62dfc5d commit b18a939

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

typing-app/docs/api-usage.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,22 @@
66

77
例えば、
88

9-
```ts
10-
// WIP
9+
```tsx
10+
import { client } from "@/libs/api";
11+
12+
async function SomePageToGetRanking() {
13+
const { data, error } = await client.GET("/scores/ranking");
14+
15+
if (error) {
16+
return <div>Error</div>;
17+
}
18+
19+
return (
20+
<div>
21+
ranking data: {JSON.stringify(data)}
22+
</div>
23+
);
24+
}
1125
```
1226

1327
のようにします。

typing-app/src/libs/api/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import createClient from "openapi-fetch";
2+
import { paths } from "./v1";
3+
4+
export const client = createClient<paths>({ baseUrl: process.env.API_URL });

0 commit comments

Comments
 (0)