@@ -21,9 +21,8 @@ Hey 👋, `@yme/api` is a package that defines the type-safe API requests. No se
21
21
## Quick Start
22
22
23
23
``` ts
24
- import { ApiClient } from " @yme/api/client" ;
24
+ import { ApiClient , replacePathParams } from " @yme/api/client" ;
25
25
import { logger } from " @yme/api/middleware" ;
26
- import { replacePathParams } from " @yme/api/client/middleware" ;
27
26
28
27
const api = new ApiClient ({
29
28
action : async ({ req }) => {
@@ -72,14 +71,23 @@ const newUserId = await createUser(
72
71
Use Next.js (Server Action)
73
72
74
73
``` ts
75
- import { NextAction } from " @yme/api/next/action " ;
74
+ import { NextAction } from " @yme/api/next" ;
76
75
const api = new NextAction ({
77
76
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
+ },
78
85
});
79
86
80
87
const updateUser = api
81
88
.post ({
82
89
// ...initial,
90
+ actionName: " updateUser" ,
83
91
})
84
92
.validator (
85
93
z .object ({
@@ -88,7 +96,11 @@ const updateUser = api
88
96
)
89
97
.bindArgs ([z .string ()])
90
98
.action (async ({ req }) => {
91
- // { bindArgs: [id], parsedInput: { name }}
99
+ const {
100
+ parsedBindArgs : [id],
101
+ parsedInput : { name },
102
+ actionName, // "updateUser"
103
+ } = req ;
92
104
return true ;
93
105
}); // updateUser(id: string, input: { name: string } | FormData): Promise<boolean>
94
106
0 commit comments