Creating Your First API
This guide will walk you through creating your first API endpoint with FLAPI.
Prerequisites
Before starting, make sure you have:
- Installed FLAPI (Quickstart Guide)
- Set up your configuration (Configuration Guide)
- 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
- Start FLAPI:
flapi serve
- Test your endpoint:
curl "http://localhost:8080/customers?search=john"
Next Steps
- Learn about authentication
- Explore caching strategies
- Set up rate limiting