FLAT
CouperSevenval TechnologiesDocker ImageGithub
develop
develop
  • 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
  • Validation
  • Configuration
  • Error Handling
  • Mocking
  • Configuration

Was this helpful?

  1. Reference
  2. OpenAPI

Upstream APIs

PreviousOpenAPINextOpenAPI

Last updated 4 years ago

Was this helpful?

Typically, FLAT uses one or more upstream APIs where it forwards requests to.

Validation

You can use Swagger to validate the use of upstream APIs, too!

The has a section on .

Configuration

The configuration takes place in the with this :

  • definition - The path to the swagger definition file (type: string)

  • validate-request - Whether to validate the request (valid values: true, false, "report-only", default: false)

  • validate-request-security - Whether to validate the request security requirements according to security in the swagger definition (valid values: true, false, "report-only", default: false)

  • validate-response - Whether to validate the response (valid values: true, false, "report-only", default: false)

Error Handling

validate-request checks that the HTTP request that is about to be sent adheres to the upstream API schema. If it doesn't, the request will not be sent. The response will be an with status 400 Bad Request.

{
  "error": {
    "message": "Upstream Request Validation Failed",
    "error": 3202,
    "status": 400,
    "requestID": "W@W8DrjPEMPxyqu4zAL4PAAAABg",
    "info": [
       "Invalid method post."
     ]
  }
}
{
  "error": {
    "message": "Upstream Request Security Validation Failed",
    "error": 3207,
    "status": 401,
    "requestID": "W@W8DrjPEMPxyqu4zAL4PAAAABg",
    "info": [
       "Header Security (HeaderAuth): Missing header My-Header"
     ]
  }
}

If validate-response detects that the response body violates the schema, the response will be replaced by a system error.

{
  "error": {
    "message": "Upstream Response Validation Failed",
    "error": 3203,
    "status": 502,
    "requestID": "W@W8DrjPEMPxyqu4zAL4PAAAABg",
    "info": [
       "Type constraint violated in body for error: Object value found, but a string is required.",
       "Upstream status: 404 Not Found"
     ]
  }
}

The informational message (array) also contains the original status code of the upstream response – in this case a 404 that may explain the problem.

In both cases, the error will be noted in $upstream/id/error where id is the content ID of the request (defaults to main).

Mocking

You can mock upstream responses, too. This is handy for writing tests or developing against upstream APIs that do not (yet) exist.

Configuration

  • definition - The path to the swagger definition file (type: string)

  • mock-response - Whether to mock the response (type: boolean, default: false)

Usually, the mock option is set dynamically:

<flow>
  <request>
  {
      "url": "https://example.com/",
      "options": {
          "definition": "upstream.yaml" {{,}}
          {{if $request/get/mock }}
            "mock-response": true
          {{end}}
      }
  }
  </request>

  <!-- process response -->
</flow>

If called with the query param mock, the example response of upstream.yaml is used:

$ curl localhost:8080/v1/…?mock

If validate-request-security is true and the request does not fullfill the security requirements, the request will not be sent. The response will be an with status 401 Unauthorized.

If the request was configured with the , errors (e.g. connection errors, invalid requests or responses) cause the normal flow to be aborted. If configured, the is run. Otherwise a standard error message is substituted as the response to the client request. See in the cookbook.

As above, we use :

It works just as . The mocked response will be used as the HTTP response body for that request.

client response mocking
tutorial
request action
more on error flows
error flow
exit-on-error option
request options
options
error document
error document
upstream validation