Tutorial
Effortless API Integration with UI Now
UI Now simplifies API development by providing a well-structured framework for creating and managing API endpoints. Any file named route.js
in the /app/api
folder automatically acts as an API endpoint, ensuring a seamless integration process.
Key Features of API Management:
Preconfigured API Client:
Use theapi.js
helper (an Axios instance with interceptors) to streamline API calls. It automatically:Displays error messages for better debugging.
Redirects users to the login page on a 401 Unauthorized error.
Adds
/api
as the base URL (e.g.,/api/user/posts
becomes/user/posts
).
Protected API Calls:
Supabase handles authentication via cookies. This means you can make secure API calls directly from the front-end without extra configuration.
Front-End Example: User Profile
The following example demonstrates how to make a protected API call from the front-end using the preconfigured API client:
File: /app/user-profile/page.js
How It Works:
The API client handles error interception and authentication.
Loading state management ensures a responsive UI.
Back-End Example: User API Endpoint
The back-end API integrates seamlessly with Supabase to handle authentication and data operations. Below is an example of an endpoint that inserts a user into the database:
File: /app/api/user/route.js
How It Works:
Supabase Authentication:
The session is automatically managed with cookies, so no manual token handling is required.Database Operations:
Insert operations are seamlessly handled via Supabase’s query builder. Ensure that ausers
table exists in your database for this call to succeed.Error Handling:
Missing data (e.g., email) is validated and returns appropriate status codes.
Server errors are logged and handled gracefully.
Unauthorized access (e.g., no active session) is blocked with a 401 response.
Why This Approach Matters:
Simplicity: Preconfigured helpers eliminate the need for repetitive setup.
Security: Supabase and Axios interceptors ensure secure and reliable API operations.
Efficiency: Focus on building features, not handling boilerplate.
With UI Now’s tools, you can create robust, secure, and scalable APIs with minimal effort, empowering solopreneurs, entrepreneurs, and agencies to launch faster.