API Engineering

What Are API Functions? Backend Route Handlers, SDK Methods & Examples

What are API functions? Discover how server controller functions, client SDK wrappers, and HTTP handlers work together to power software integrations.

By Cometflow API Engineering Team • Updated 2026-11-12

When developers speak about api functions, they typically refer to one of two things: the backend controller or serverless functions that handle incoming HTTP routes, or the client-side software development kit (SDK) functions that wrap network requests in clean, reusable syntax.

1. Server-Side API Functions (Route Handlers & Serverless Endpoints)

On the backend, an api function is the executable routine bound to an HTTP method and route path (such as POST /api/v1/invoices). In Express, Next.js, Cloudflare Workers, or FastAPI, it accepts a request object, validates input, performs database logic, and returns a structured JSON response:

// Server-side API Function in TypeScript
export async function handleCreateInvoice(req: Request, res: Response) {
  try {
    const { customerId, items, currency } = req.body;
    
    // 1. Validation function
    validateInvoicePayload({ customerId, items });

    // 2. Database business logic
    const invoice = await db.invoices.create({
      data: { customerId, items, currency, status: 'unpaid' }
    });

    // 3. Return response function
    return res.status(201).json({ success: true, invoice });
  } catch (err) {
    return res.status(400).json({ error: err.message });
  }
}

2. Client-Side API Functions (SDK Wrappers)

On the frontend, calling raw fetch() repeatedly across dozens of components is error-prone. Engineers encapsulate network calls into typed api functions:

// Client API function SDK
export const api = {
  getProfile: (userId: string) => 
    fetch(`/api/users/${userId}`).then(r => r.json()),
    
  updateAvatar: (userId: string, file: File) => {
    const form = new FormData();
    form.append('avatar', file);
    return fetch(`/api/users/${userId}/avatar`, { method: 'POST', body: form });
  }
};

Well-organized api functions keep frontend code clean, reduce boilerplate, and centralize error handling and authentication token refreshes in one place. Want to test live HTTP endpoints? Visit our Interactive API Examples Hub or 15 Real-World API Online Examples.

Frequently Asked Questions

What are API functions in web development?

API functions refer to two complementary layers: (1) server-side route handlers or serverless functions (e.g., handleCreateInvoice(req, res)) that validate incoming HTTP requests, run database queries, and return JSON responses, and (2) client-side SDK wrapper functions (e.g., api.getUserProfile(id)) that encapsulate fetch() calls, headers, and error handling.

What is the difference between an API function and an HTTP method?

An HTTP method (GET, POST, PUT, PATCH, DELETE) is the standard protocol verb sent over the network, whereas an API function is the actual JavaScript, TypeScript, Python, or Go code executed on the client or server when that endpoint is invoked.