Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 3.24 KB

rest.md

File metadata and controls

66 lines (49 loc) · 3.24 KB

REST APIs

REST is Flow's default. A REST API addresses resources by URL path and acts on them with HTTP methods (GET, POST, PUT, PATCH, DELETE); that is ordinary HTTP, so Flow carries it with no special configuration — a route to a backend is all it takes.

New here? Start with Traffic & APIs for the overview, or Getting Started. For a complete, runnable REST config, see examples/rest-api-gateway.kdl in Examples.

How Flow handles a REST request

Flow reads the HTTP envelope — method, path, headers, status — and forwards the body unchanged. For each request it:

  1. Matches a route by path (and optionally host or header), then scores the best match. See Routing.
  2. Checks the method against the route's allowed-methods; a method the route does not allow is refused.
  3. Applies policies — authentication, rate limiting, header rewriting, size limits, caching.
  4. Forwards the request to the selected backend and streams the response back.

The JSON (or other) body is never parsed or validated — it passes through byte-for-byte.

route {
    name "users-api"
    match {
        path-prefix "/api/v1/users"
    }
    allowed-methods "GET" "POST" "PUT" "PATCH" "DELETE"
    connectors {
        "users-backend.internal:8080"
    }
}

What applies to a REST route

Each of these is owned by its own page; a REST route uses them like any other HTTP route:

Concern Where
Path matching, prefixes, regex, scoring Routing
Allowed methods per route Routing, Configuration
Request / response header rewriting Header transform
Path / URI rewriting URI transform
Request and response body size limits Request size limit, Response size limit
Caching GET responses Response caching
Redirects (HTTPS enforcement, moved paths, version moves) Redirect
Error responses Flow returns (4xx / 5xx) How Flow Behaves
Throughput and latency Performance

What's coming for REST

Flow forwards REST bodies untouched today. Deeper, REST-aware handling is on the roadmap:

Planned: request and response body transformation (bodies pass through unchanged today). See Roadmap.

Planned: request validation against an OpenAPI schema. See Roadmap.

Evaluating: gRPC transcoding — letting REST and JSON clients call gRPC backends through Flow. See Roadmap.

See also