Example 4: Built-in REST API

No code required - Genes handles everything automatically!

✨ Zero Custom Code!

This example has no custom API handlers. All CRUD operations are handled by Genes' built-in API system at /api/* routes.

Built-in API Endpoints

Genes automatically provides REST endpoints for all 5 database tables.

Basic CRUD

GET /api/items

List all items

GET /api/items/:hash

Get single item

POST /api/items

Create new item

PUT /api/items/:hash

Update item

DELETE /api/items/:hash

Delete item

Advanced Features

GET /api/items?filters[type]=todo

Filter by field

GET /api/items?page=1&limit=10

Pagination

GET /api/items?order=created_at DESC

Sorting

GET /api/items?search=keyword

Full-text search

All Tables Supported

  • /api/items - Content (posts, todos, products, etc)
  • /api/persons - Users and accounts
  • /api/labels - Categories and tags
  • /api/clones - Projects/instances
  • /api/events - Activity log

Complete Implementation

<?php
require_once 'genes.php';

// Setup database
g::run("db.connect", array(
    "driver" => "sqlite",
    "database" => "app.db"
));

// That's it! API is ready at /api/*
g::run("route.handle");

That's the entire implementation. Genes handles everything!

Try It Out

Create, update, and delete todos using the built-in API

Your Todos

Loading todos...

API Calls Log


                        

Built-in API vs Custom Implementation

✅ Built-in API (This Example)

  • Zero code - just configure database
  • Automatic CRUD on all 5 tables
  • Built-in validation
  • Pagination & search included
  • Filter support out-of-the-box
  • Consistent response format
  • Production-ready immediately

🔧 Custom API (Example 3)

  • Full control over logic
  • Custom business rules
  • Specialized validation
  • Custom endpoints/routes
  • Non-standard operations
  • Learning exercise
  • When you need specific behavior

Use built-in API for standard CRUD. Use custom implementation when you need special logic.