Skip to content

Commit d582c0f

Browse files
committed
docs: update readme.md
1 parent 626c448 commit d582c0f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

packages/api/readme.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ Hey 👋, `@yme/api` is a package that defines the type-safe API requests. No se
2121
## Quick Start
2222

2323
```ts
24-
import { ApiClient } from "@yme/api/client";
24+
import { ApiClient, replacePathParams } from "@yme/api/client";
2525
import { logger } from "@yme/api/middleware";
26-
import { replacePathParams } from "@yme/api/client/middleware";
2726

2827
const api = new ApiClient({
2928
action: async ({ req }) => {
@@ -72,14 +71,23 @@ const newUserId = await createUser(
7271
Use Next.js (Server Action)
7372

7473
```ts
75-
import { NextAction } from "@yme/api/next/action";
74+
import { NextAction } from "@yme/api/next";
7675
const api = new NextAction({
7776
middlewares: [],
77+
// throwing an error will make the server return status 500
78+
// we can handle it in the error handler. e.g. returns a fallback data with error message
79+
handleError: async (err, opts) => {
80+
return {
81+
message: err.message,
82+
code: err.code,
83+
};
84+
},
7885
});
7986

8087
const updateUser = api
8188
.post({
8289
// ...initial,
90+
actionName: "updateUser",
8391
})
8492
.validator(
8593
z.object({
@@ -88,7 +96,11 @@ const updateUser = api
8896
)
8997
.bindArgs([z.string()])
9098
.action(async ({ req }) => {
91-
// { bindArgs: [id], parsedInput: { name }}
99+
const {
100+
parsedBindArgs: [id],
101+
parsedInput: { name },
102+
actionName, // "updateUser"
103+
} = req;
92104
return true;
93105
}); // updateUser(id: string, input: { name: string } | FormData): Promise<boolean>
94106

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const api = new NextAction({
8787
const updateUser = api
8888
.post({
8989
// ...initial,
90+
actionName: "updateUser",
9091
})
9192
.validator(
9293
z.object({
@@ -98,6 +99,7 @@ const updateUser = api
9899
const {
99100
parsedBindArgs: [id],
100101
parsedInput: { name },
102+
actionName, // "updateUser"
101103
} = req;
102104
return true;
103105
}); // updateUser(id: string, input: { name: string } | FormData): Promise<boolean>

0 commit comments

Comments
 (0)