You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/03-Customization/06-customPages.md
+35-35Lines changed: 35 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -303,38 +303,6 @@ Now we have to define this endpoint in the backend to make our page work:
303
303
304
304
## Defining custom API for own page and components
305
305
306
-
> ☝️ Using `admin.express.withSchema(...)` is the recommended approach because it adds your route to `/api/v1/openapi.json` and `/api-docs` (Solar), performs early runtime validation for API calls, and gives agent plugins a machine-readable API contract they can use in skills. It is still optional though, and you can register plain Express routes without `withSchema(...)` if you prefer.
307
-
308
-
> ☝️ If you do not want to use Zod, you can pass a plain JSON Schema object instead of a Zod schema. For example, this Zod response schema:
Open `index.ts` file and add the following code *BEFORE* `admin.express.serve(` !
@@ -458,15 +426,47 @@ admin.discoverDatabases();
458
426
459
427
Install and import Zod before using this pattern: `pnpm add zod` or `npm install zod`, then `import*aszfrom'zod';`. `admin.express.withSchema(...)` will convert the Zod schema to OpenAPI for you.
460
428
429
+
If you created the app with the CLI defaults, start it and open `http://localhost:3500/api-docs` in your browser to see this custom method in the generated API docs.
430
+
461
431
462
432
> ☝️ Please note that we are using `admin.express.authorize` middleware to check if the user is logged in. If you want to make this endpoint public, you can remove thismiddleware. If user is not logged in, the request will return401 Unauthorized status code, and protect our statistics from leak.
463
433
464
434
> ☝️ Moreover if you wrap your endpoint with`admin.express.authorize` middleware, you can access `req.adminUser` object in your endpoint to get the current user information.
465
435
466
-
> ☝️ Wrapping the route with `admin.express.withSchema(...)` registers it in `/api/v1/openapi.json` and `/api-docs`. Define custom routes before `admin.express.serve(app)` so AdminForth can pick them up.
436
+
> ☝️ Using `admin.express.withSchema(...)` is the recommended approach because it adds your route to `/api/v1/openapi.json` and `/api-docs` (Solar), performs early runtime validation forAPI calls, and gives agent plugins a machine-readable API contract they can use inskills. It is still optional though, and you can register plain Express routes without `withSchema(...)`if you prefer.
437
+
438
+
> ☝️ If you do not want to use Zod, you can pass a plain JSONSchema (or convert it from e.g. typebox) object instead of a Zod schema. For example, this Zod response schema:
> ☝️ AdminForth does not provide any facility to access data in database. You are free to use any ORM like Prisma, TypeORM, Sequelize,
469
-
mongoose, or just use raw SQL queries against your tables.
469
+
> ☝️ AdminForth does provide own data access facility called [DATAAPI](./11-dataApi.md) to access data indatabase. But it is very basic and mostly covers only simple CRUDoperations. For complex queries like inthis example, it is better to use your own data access code with any ORM. You are free to use any ORM like Prisma, TypeORM, Sequelize, mongoose, or just use raw SQL queries against your tables.
0 commit comments