@@ -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" ;
2525import { logger } from " @yme/api/middleware" ;
26- import { replacePathParams } from " @yme/api/client/middleware" ;
2726
2827const api = new ApiClient ({
2928 action : async ({ req }) => {
@@ -72,14 +71,23 @@ const newUserId = await createUser(
7271Use Next.js (Server Action)
7372
7473``` ts
75- import { NextAction } from " @yme/api/next/action " ;
74+ import { NextAction } from " @yme/api/next" ;
7675const 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
8087const 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
0 commit comments