Skip to main content

Creating Your First API

This guide will walk you through creating your first API endpoint with FLAPI.

Prerequisites

Before starting, make sure you have:

  1. Installed FLAPI (Quickstart Guide)
  2. Set up your configuration (Configuration Guide)
  3. A SQL database or data source to connect to

Step 1: Create Your SQL Template

Create a new file sqls/customers.sql in your project:

SELECT 
customer_id,
first_name,
last_name,
email
FROM customers
WHERE
{% if request.query.search %}
(first_name ILIKE '%' || :search || '%' OR
last_name ILIKE '%' || :search || '%')
{% endif %}
LIMIT 100;

Step 2: Configure the Endpoint

Create sqls/customers.yaml to configure the endpoint:

method: GET
path: /customers
description: List customers with optional search
parameters:
- name: search
in: query
required: false
schema:
type: string

Step 3: Test Your API

  1. Start FLAPI:
flapi serve
  1. Test your endpoint:
curl "http://localhost:8080/customers?search=john"

Next Steps