Documentation is currently in beta. Report issues →
API ReferenceOverview

API Reference Overview

Y3NKO uses a combination of Next.js API Routes and Server Actions for data operations.

API Design Principles

  1. RESTful conventions where practical
  2. Server Actions for mutations from React components
  3. API Routes for webhooks and external integrations
  4. Consistent error handling with proper status codes
  5. Type-safe with Zod validation

When to Use What

Use CaseSolution
Reading data in Server ComponentsDirect Prisma queries
Mutations from formsServer Actions
Webhooks (Paystack, etc.)API Routes
External integrationsAPI Routes
Client-side data fetchingAPI Routes + fetch

Base URL

Development: http://localhost:3000/api
Production:  https://y3nko.travel/api

Request Format

All POST/PATCH/PUT requests expect JSON:

POST /api/bookings
Content-Type: application/json
 
{
  "listingId": "clx123...",
  "checkIn": "2024-03-15",
  "checkOut": "2024-03-18"
}

Response Format

Success Response

{
  "data": {
    "id": "clx123...",
    "reference": "Y3K-ABC123",
    "status": "PENDING"
  }
}

List Response with Pagination

{
  "data": [
    { "id": "clx1...", "title": "Beach Villa" },
    { "id": "clx2...", "title": "Mountain Lodge" }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 156,
    "totalPages": 8,
    "hasMore": true
  }
}

Error Response

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Check-out date must be after check-in date",
    "details": {
      "field": "checkOut",
      "constraint": "date_after"
    }
  }
}

Authentication

Most endpoints require authentication. Include the session cookie (automatically handled by the browser) or pass the access token:

GET /api/bookings
Cookie: sb-access-token=eyJ...

For API-to-API calls:

GET /api/bookings
Authorization: Bearer eyJ...

Rate Limiting

Endpoint TypeLimit
Public GET100/minute
Authenticated GET200/minute
POST/PATCH/DELETE30/minute
Auth endpoints10/minute

Rate limit headers are included in responses:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1709912345

Validation

All inputs are validated server-side using Zod schemas:

// lib/validators.ts
import { z } from 'zod'
 
export const createBookingSchema = z.object({
  listingId: z.string().cuid(),
  checkIn: z.string().datetime(),
  checkOut: z.string().datetime(),
  adults: z.number().int().min(1).max(20),
  children: z.number().int().min(0).max(10).default(0),
  guestName: z.string().min(2).max(100),
  guestEmail: z.string().email(),
  guestPhone: z.string().regex(/^\+233[0-9]{9}$/),
}).refine(
  data => new Date(data.checkOut) > new Date(data.checkIn),
  { message: "Check-out must be after check-in" }
)

Common Parameters

Pagination

ParameterTypeDefaultDescription
pagenumber1Page number
limitnumber20Items per page (max 50)

Sorting

ParameterTypeOptionsDescription
sortstringprice_asc, price_desc, newest, popularSort order

Date Ranges

ParameterTypeFormatDescription
checkInstringISO 8601Start date
checkOutstringISO 8601End date

API Endpoints Summary

Public Endpoints

MethodEndpointDescription
GET/api/listingsList accommodations
GET/api/listings/[slug]Get listing details
GET/api/listings/featuredGet featured listings
GET/api/destinationsList destinations

Authenticated Endpoints

MethodEndpointDescription
GET/api/bookingsList user’s bookings
POST/api/bookingsCreate booking
GET/api/bookings/[ref]Get booking details
POST/api/bookings/[ref]/cancelCancel booking
GET/api/favoritesList favorites
POST/api/favorites/toggleToggle favorite

Payment Endpoints

MethodEndpointDescription
POST/api/payments/initializeInitialize payment
GET/api/payments/[ref]/statusCheck payment status
POST/api/webhooks/paystackPaystack webhook

Admin Endpoints

MethodEndpointDescription
GET/api/admin/bookingsList all bookings
POST/api/admin/listingsCreate listing
PATCH/api/admin/listings/[id]Update listing
DELETE/api/admin/listings/[id]Delete listing

Server Actions are preferred for mutations in React components. API routes are used for webhooks and external integrations.