Next.js
Run bknd inside Next.js
Installation
To get started with Next.js and bknd you can either install the package manually, and follow the descriptions below, or use the CLI starter:
Create a new Next.js CLI starter project by running the following command:
Create a new Next.js CLI starter project by running the following command:
Create a new Next.js project by following the official guide, and then install bknd as a dependency:
Serve the API
Create a helper file to instantiate the bknd instance and retrieve the API:
For more information about the connection object, refer to the Database guide.
Now to expose the API, create a catch-all route file at src/api/[[...bknd]]/route.ts
:
Enabling the Admin UI
Create a page at admin/[[...admin]]/page.tsx
:
Example usage of the API
You can use the getApi
helper function we’ve already set up to fetch and mutate in static pages and server components: