FLAT
CouperSevenval TechnologiesDocker ImageGithub
master
master
  • Changelog
  • FLAT
  • Administration
    • Configuration
    • Docker
    • Logging
  • Cookbook
    • Using the Built-in Mocking
    • Performing Additional Checks on JWT Access Tokens
    • Logging Custom Fields
    • Using Environment Variables
    • Handling Errors with an Error Flow
    • File Serving
    • Forwarding a Request to an Upstream API
    • Extracting Common Initialization Flow Tasks
    • Encoding and Decoding JWT
    • Passing Header Fields to the Client
    • How can I pass an arbitrary header field to an upstream system?
    • Performing Additional Checks on JWT Access Tokens
    • Proxying requests to Upstream APIs
    • Increasing the Request Timeout
    • How can I see what the client requested?
    • Using Swagger UI for API Documentation
    • Testing API Requests
    • Testing with Backend Requests
    • Testing Templates
    • Sending POST Requests
    • Processing Upstream Responses
    • Protecting Access using JWT Tokens
  • Reference
    • Configuration
    • Debugging
    • flat CLI
    • Flow
    • Variables
    • OpenAPI / Swagger Integration
    • OpenAPI
      • CORS - Cross-Origin Resource Sharing
    • OpenAPI
      • Differences from Swagger
    • OpenAPI
      • Mocking
    • OpenAPI
      • Routing
    • OpenAPI
      • Security
    • OpenAPI
      • Upstream APIs
    • OpenAPI
      • Validation
    • Flow Actions
      • assert Action
      • auth Action
      • backend-flow Action
      • copy Action
      • debug Action
      • dump Action
      • echo Action
      • error Action
      • eval Action
      • log Action
      • nameshave Action
      • pass-body Action
      • proxy-request Action
      • regex Action
      • request Action
      • requests Action
      • serve Action
      • set-config Action
      • set-env Action
      • set-response-headers Action
      • set-status Action
      • sub-flow Action
      • template Action
      • test-request Action
      • xslt Action
    • Functions
      • apply-codecs()
      • array-reverse()
      • array()
      • base64-decode()
      • base64-encode()
      • body()
      • calc-signature()
      • capitalize-first()
      • content()
      • decrypt-xml()
      • decrypt()
      • encrypt()
      • ends-with()
      • file-exists()
      • fit-document()
      • fit-log()
      • fit-serialize()
      • get-log()
      • has-class()
      • html-parse()
      • join()
      • json-doc()
      • json-parse()
      • json-stringify()
      • json-to-csv()
      • json-to-xml()
      • jwt-decode()
      • jwt-encode()
      • ldap-lookup()
      • ldap-query()
      • lookup()
      • matches()
      • md5()
      • replace()
      • sort()
      • split()
      • tolower()
      • toupper()
      • trim()
      • unixtime()
      • urldecode(), url-decode()
      • urlencode(), url-encode()
      • uuid3() and uuid4()
      • verify-signature()
      • verify-xmldsig()
      • xml-parse()
      • xml-to-json()
    • Templating
      • {{,}}
      • Comment {{// …}}
      • Dot {{.}}
      • Conditional `{{if <condition>}} … {{elseif <condition> }} … {{else}} … {{end}}
      • loop
      • ?? Operator
      • Object XML Notation (OXN)
      • Pair Producer {{: …}}
      • Placeholder
      • Template Variables
      • with
    • Testing
  • Tutorial
Powered by GitBook
On this page
  • Assigning FLAT Flows
  • Fallback Flow
  • Init Flow
  • Error Flow
  • Default Flow
  • Assigning FLAT Proxies
  • Path Parameters

Was this helpful?

  1. Reference
  2. OpenAPI

Routing

An API definition must provide a list of callable paths – sometimes also called routes or endpoints.

In swagger.yaml this is defined in the paths section:

swagger: "2.0"
info:
  description: "…"
  version: "1.0.0"
  title: "My API"
basePath: "/v1"
paths:
  /users:
    get:
      responses:
        200:
          description: "Get a list of all users"
    post:
      responses:
        201:
          description: "User created"
  /dashboard:
    get:
      …

One important setting is the basePath property. All described API paths are only accessible below that basePath.

In general, only the paths that are explicitly defined are permissible, i.e. they may not be extended arbitrarily.

In our example, the following paths are valid:

/v1/users
/v1/dashboard

While these are undefined (especially those pointing outside of base path):

/v1
/users
/v1/users/too/long
…
basePath: "/v1"
paths:
  /users:
    …
  /users/**:
    # Wildcard path matching /v1/users/…
  /dashboard:
    …

Assigning FLAT Flows

paths:
  /users:
    get:
      # flow for GET /users
      x-flat-flow: api/users.xml
      responses:
        200:
          description: "Get a list of all users"
    post:
      # flow for POST /users
      x-flat-flow: api/create-user.xml
      responses:
        201:
          description: "User created"
  /dashboard:
    # flow for /dashboard (all methods)
    x-flat-flow: api/dashboard.xml
    get:
      …

You can specify a flow for a path (as in /dashboard) or for specific methods/operations (as in /users). The same flow can be used for multiple paths or methods.

Fallback Flow

An x-flat-flow property set directly in the paths object behaves as a fallback flow. If the incoming request has matched a defined path, but that path did not define a flow, the fallback flow will be executed:

paths:
  x-flat-flow: api/fallback.xml

Init Flow

…
x-flat-init: init.xml
paths:
  /users:
    get:
…

For requests outside of the API basePath (e.g. / or /assets), the init flow is not executed. It is only called for API requests.

Error Flow

…
x-flat-error:
  flow: error.xml
…

Default Flow

Assigning FLAT Proxies

A simpler way to achieve this is by using x-flat-proxy in the swagger.yaml:

basePath: /api
paths:
  /users/**:
    x-flat-proxy:
      origin: https://users.upstream.example.com
      stripEndpoint: true
      addPrefix: /v4
      headers:
        Correlation-ID: 42
      options:
        timeout: 2
        definition: users-upstream.yaml
        validate-response: report-only

x-flat-proxy can be used below paths, paths/<path> and paths/<path>/<operation>.

x-flat-proxy and x-flat-flow are alternatives and cannot be used in combination.

Path Parameters

Swagger paths can define path parameters:

paths:
  /users/{userid}:
    x-flat-flow: api/user-info.xml
    …
<template>
{
  "user": {
    "name": {{ $request/params/userid }}
  }
}
</template>
PreviousOpenAPINextOpenAPI

Last updated 5 years ago

Was this helpful?

The Swagger docs have more information on .

To skirt the rule that every single permissible path must be defined, you can use FLAT's to match arbitrarily long request paths. Wildcard paths, i.e. paths ending with /**, match all paths sharing the same prefix. For example, by adding the wildcard path /users/** to the above definition, the formerly undefined path /v1/users/too/long will be matched, too, as well as any other path starting with /v1/users/:

In FLAT you can assign a file to every API path to define the request processing. This is done with the x-flat-flow property:

An init flow is a separate flow file that is executed before the regular or defined for an API path. It is specified by setting x-flat-init on the top level in the OpenAPI definition:

The init flow can be used to , e.g. initialize variables or set HTTP response headers.

A statement in the init flow terminates the whole request; the regular flow (specified by x-flat-flow) is not executed. A statement terminates only the init flow; the regular flow is executed. Terminating like or will prevent the actual flow from being executed, too.

An error flow is an optional separate flow file that is executed if a client request or response validation error has occurred, or if the exit-on-error option was set for a , or that has failed. It is specified by setting the flow property of x-flat-error on the top level in the OpenAPI definition:

The error flow can be used to . Note that the output generated after the error flow has run will not be validated. Additionally, errors encountered while the error flow is processed will not re-start the error flow.

Requests to resources outside the basePath are handled by the default flow defined in conf/flow.xml. This allows for and the like.

If FLAT acts as a proxy for an upstream API on a specific route, you could assign a flow containing a .

A client request to https://client.example.com/api/users/profile will be proxied to https://users.upstream.example.com/v4/profile. See for more information about /**.

The configuration for x-flat-proxy is the same as that for a (translated from JSON to YAML syntax).

If configured, the is executed before the proxy request. If configured, the is executed if the exit-on-error option was set and the proxy request fails.

All named params are available from inside the flow in the pre-defined as properties of the $request/params object:

paths and operations
flow
extract common initialization tasks
produce error messages with a custom format or status
serving HTML, images, JavaScript
proxy-request action
proxy-request action
flow
configured proxy
request
proxy-request
configured proxy
init flow
error flow
actions
echo
dump
break
return
variable $request
wildcard path feature
wildcard paths