Building a Full-Stack Next.js Application with Gibson AI
Introduction
This tutorial walks you through creating a simple to-do application using Next.js with Gibson AI as your database solution.
Setting Up Your Project
Clone the template repository by running:
Run the setup script in your terminal. When prompted, name your project (e.g., "to-do-app").
Configure environment variables:
Copy your Gibson API key from the settings section
Deploy your data model in Gibson to generate API endpoints
Get your OpenAPI specification URL from the API documentation page
Using the Gibson Client
Gibson offers multiple ways to interact with your database:
Using tRPC Procedures:
Import the Gibson client in your tRPC router
Create type-safe procedures with runtime validation
Access data using React Query hooks for loading and error states
Using Next.js API Routes:
Create custom endpoints in the
/api/http
directoryImplement validation and business logic
Make direct calls to the Gibson API
Using Server Components:
Create async server components with the
async function
syntaxMake direct Gibson API calls before rendering
Return fully rendered content without loading states
Using Server Actions:
Create server-side functions marked with
"use server"
Call these functions from client components
Use React state to handle loading and updating the UI
Example: Fetching User Data
Create a route by adding a new directory (
/demo
) with apage.tsx
file.Import the Gibson client and create a function to fetch user data:
Display the data in your component with proper error and loading handling.
Remember that your API key is safe when used in server components or actions, as they execute only on the server.