1. Proxies and Flow

api

Version

The main API configuration. Extends serviceProxy with REST and OpenAPI support and expression-based routing.

Several APIs can share one port and are told apart by host, path, or a test expression. Incoming requests are probed from the first API to the last; the first one that matches handles the request.

When openapi children are present, Membrane deploys the described API and publishes its specifications at /api-docs. The path from the OpenAPI servers field determines where the API is reachable. Requests are forwarded to the explicit target when one is configured; otherwise Membrane forwards to the host from the OpenAPI servers field. See tutorials/getting-started/80-OpenAPI.yaml and tutorials/getting-started/90-OpenAPI-Validation.yaml.

Example Configuration

# Basic path routing
api:
port: 2000
path:
uri: /products
target:
url: https://api.predic8.de

---
# URI template routing
api:
port: 2000
path:
uri: /orders/{id}
target:
url: https://api.predic8.de/shop/orders/{pathParam.id}

---
# Custom routing with expression
api:
port: 2000
test: header.SOAPAction == 'https://predic8.de/city-service/get'
target:
url: https://api.predic8.de/city-service

---
# OpenAPI support
api:
port: 2000
openapi:
- location: openapi/fruitshop-api.yaml
validateRequests: true
validateResponses: true
# Basic path routing
 api:
   port: 2000
   path:
     uri: /products
   target:
     url: https://api.predic8.de

 ---
 # URI template routing
 api:
   port: 2000
   path:
     uri: /orders/{id}
   target:
     url: https://api.predic8.de/shop/orders/{pathParam.id}

 ---
 # Custom routing with expression
 api:
   port: 2000
   test: header.SOAPAction == 'https://predic8.de/city-service/get'
   target:
     url: https://api.predic8.de/city-service

 ---
 # OpenAPI support
 api:
   port: 2000
   openapi:
     - location: openapi/fruitshop-api.yaml
       validateRequests: true
       validateResponses: true

Syntax

api:
'$ref': <string>
description: <string>
flow:
- <flow>
host: <string>
id: <string>
ip: <string>
language: groovy
method: <string>
name: <string>
openapi:
- <openapi>
path: {}
port: <number>
ssl: {}
target: {}
test: <string>
xmlConfig: {}
api:
  '$ref': <string>
  description: <string>
  flow:
    - <flow>
  host: <string>
  id: <string>
  ip: <string>
  language: groovy
  method: <string>
  name: <string>
  openapi:
    - <openapi>
  path: {}
  port: <number>
  ssl: {}
  target: {}
  test: <string>
  xmlConfig: {}

Attributes

NameRequiredDefaultDescriptionExamples
$reffalse-Reference a component defined under components.-
hostfalsenot setRestricts to requests whose Host header matches one of the given hostnames. Separate multiple hostnames with spaces. The asterisk * matches any number of characters, including zero, for basic globbing.predic8.de *.predic8.de
idfalse-Identifier for this API. Overrides the auto-generated entry id used for this API in the published apis.json catalog; otherwise an id is derived from the API's key.order-api
ipfalsenot setIf present, binds the port only on the specified IP. Useful for hosts with multiple IP addresses.127.0.0.1
languagefalseSpELExpression language used to evaluate the test attribute.-
methodfalse*Restricts this proxy to requests whose HTTP method (GET, POST, etc.) matches. The asterisk * matches any method.GET
namefalseBy default, a name will be automatically generated from the target host, port, etc.The name as shown in the Admin Console.-
portfalse80The port Membrane listens on for incoming connections.8080
testfalse-Expression evaluated against each request; the API matches only when it returns true. Used to discriminate APIs on the same port beyond host and path, e.g. by header or method.header.SOAPAction == 'https://predic8.de/city-service/get'

Child Structure

ElementCardinalityDescription
description0..1Human-readable description of the API.
flow0..*
openapi0..*Deploys the API described by an OpenAPI document: the document is published under /api-docs and, when configured, requests and responses are validated against it.
path0..1Restricts to requests whose path matches, either by prefix (starts-with) or, when enabled, by regular expression. In a soapProxy, setting a path also rewrites the paths of SOAP requests and the service addresses in the WSDL accordingly.
ssl0..1Configures inbound or outbound SSL connections.
target0..1The backend server that requests are forwarded to after passing through the flow.
xmlConfig0..1XML configuration for the API, such as namespace declarations used by XPath expressions.

Can be used in

No parent elements.