Camel Components

REST Postman

Since Camel 4.23

Both producer and consumer are supported

The REST Postman component configures rest producers and contract-first rest consumers from a Postman Collection, and delegates to a component implementing the RestProducerFactory interface. Currently, known working components are:

It is the Postman equivalent of rest-openapi. Use it when a Postman Collection is the description of the API you have, rather than an OpenAPI specification.

Only the Postman Collection Format v2.1 is supported.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-rest-postman</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

rest-postman:[collectionSource#]requestId

collectionSource is either a resource URI of a Collection v2.1 JSON document (classpath:, file: or http:), or the uid of a collection to fetch from the Postman cloud. It defaults to postman-collection.json on the classpath.

requestId selects what to invoke:

Fragment Selects

getPetById

the single request whose name slugifies to getPetById

pets/addPet

the request Add Pet inside the folder Pets, used when a name is not unique

3f2504e0-4f89-11d3-9a0c-0305e82c3301

the request with that id, which only collections fetched from the cloud carry

pets

every request in the folder Pets

pets/

the folder Pets, forced, for when a request and a folder share a name

omitted

every request in the collection

This component’s endpoint URI is lenient, which means that in addition to message headers you can specify a request’s parameters as endpoint parameters. These will be constant for all subsequent invocations, so it makes sense to use this feature only for parameters that are indeed constant for all invocations.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The REST Postman component supports the following options which are listed below.

Name Description Default Type

basePath (common)

The base path of the API, for example /v2, in front of the path of every request, and the path the consumer serves the requests under. If not set, the context path of the REST configuration is used, or else the path that the host of the request URL carries, such as /v1 when \{{baseUrl}} is https://api.example.com/v1.

String

collectionSource (common)

The Postman Collection to use, when it is not given on the endpoint. Either a resource URI of a Collection v2.1 JSON document (classpath:, file: or http:), where a name without a scheme is loaded from the classpath, or the uid of a collection to fetch from the Postman cloud.

String

collectionSourceType (common)

How to interpret collectionSource. With auto, a bare collection UUID or {ownerId}-{uuid} is fetched from the Postman cloud and anything else is resolved as a resource (classpath:, file:, http:). Use resource or cloud to decide explicitly.

Enum values:

  • auto

  • resource

  • cloud

auto

String

variables (common)

Values for the \{{variable}} placeholders used in the collection. These override the variables declared by the collection and its folders. This is a multi-value option with prefix: variable.

Map

failOnUnresolvedVariable (common (advanced))

Whether to fail when a \{{variable}} placeholder used by a selected request cannot be resolved. When false the placeholder is left as-is in headers and bodies, while one left in the URL, the query parameters, Accept or Content-Type fails anyway.

false

boolean

apiContextPath (consumer)

The path, below the base path, on which the consumer serves the collection document as JSON, for example /postman.json. The auth blocks are removed from the document and the values of secret variables are replaced. If not set, the document is not served.

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

clientRequestValidation (consumer)

Whether the consumer validates the incoming requests. A Postman collection has no schemas, so this is a best-effort check: the headers the request declares, the query parameters that have a value in the collection, a body when the collection has one, and the media types. It is also enabled by clientRequestValidation of the REST configuration.

false

boolean

missingRequest (consumer)

What the consumer does with a request of the collection that has no route consuming from the direct endpoint named after the request id, such as direct:getUserById. With fail the route does not start, with ignore a warning is logged and such a request goes on to the route of this endpoint as is, and with mock it is answered with a saved example response of the collection, or else a file found by mockIncludePattern. If not set, it is mock when the Camel profile is dev, and fail otherwise.

Enum values:

  • fail

  • ignore

  • mock

fail

String

consumerComponentName (consumer (advanced))

Name of the Camel component that serves the HTTP requests, which must implement the RestOpenApiConsumerFactory SPI, as platform-http does. If not set, a component with that capability already in the Camel context is used, or else platform-http.

String

mockIncludePattern (consumer (advanced))

Comma separated Ant-style patterns of the files that missingRequest=mock answers from, for a request without a saved example response in the collection. A file is used when its path without the extension ends with the request path, such as camel-mock/pets/1.json for GET /pets/1.

classpath:camel-mock/**

String

requestFilter (consumer (advanced))

Filters which requests of the collection are used, by the consumer and the producer, as comma separated Ant-style patterns matched against the folder qualified slug of the request, such as users/getUserById. Prefix a pattern with ! to exclude; with only exclusions, every other request is kept.

String

restPostmanProcessorStrategy (consumer (advanced))

A custom strategy for how the consumer services the requests of the collection: which route each request is dispatched to, the mock responses and the collection document. The default strategy dispatches each request to the direct endpoint named after the request id, such as direct:getUserById.

RestPostmanProcessorStrategy

host (producer)

The scheme, host name and port to send the requests to, in the form http[s]://hostname[:port]. If set, it replaces the host of every request URL in the collection. If not set, the host comes from the request URL, then from the REST configuration, and for a collection loaded over HTTP from the address it was loaded from.

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

runFailFast (producer)

When the endpoint runs more than one request, that is when it selects a folder or the whole collection, whether to stop and fail on the first request that fails. When false every request is attempted and the failure is recorded in its result.

true

boolean

componentName (producer (advanced))

Name of the Camel component that performs the HTTP requests, which must implement the RestProducerFactory SPI, as http, vertx-http, undertow and netty-http do. If not set, a component with that capability already in the Camel context or the registry is used, or else the first of http, vertx-http, undertow and netty-http on the classpath.

String

consumes (producer (advanced))

The media type accepted in the response, sent as the Accept HTTP header. If not set, the Accept header of the request in the collection is used, when it has one. A Postman collection does not describe responses, so there is nothing else to infer it from.

String

produces (producer (advanced))

The media type of the request body, sent as the Content-Type HTTP header. If not set, the Content-Type header of the request in the collection is used, or else a type inferred from its body mode, such as application/json for a raw JSON body.

String

queryParameterMode (producer (advanced))

How to treat the query parameters declared in the collection. With placeholder the parameter names are bound to message headers and the values in the collection are ignored as sample data. With literal the values in the collection are sent as-is.

Enum values:

  • placeholder

  • literal

placeholder

String

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

collectionCacheTtl (advanced)

How long, in milliseconds, a loaded collection stays in the cache of the component, so that endpoints over the same collection load it once. A negative value keeps it until the component stops. The collection is read when a producer or consumer is created, so a running endpoint does not pick up changes.

-1

long

configuration (advanced)

The shared configuration used as the template for every endpoint created by this component.

RestPostmanConfiguration

connectTimeout (advanced)

Connection timeout in milliseconds when fetching a collection from the Postman cloud.

15000

long

requestTimeout (advanced)

Request timeout in milliseconds when fetching a collection from the Postman cloud.

30000

long

collectionAuth (security)

What to do with the auth block the collection declares for the target API. With ignore the block is not applied, and a warning names the type that was found. With header the basic, bearer and apikey types are applied as a static header or query parameter, and any other type fails at startup rather than silently sending no credential. With fail any auth block other than noauth is rejected.

Enum values:

  • ignore

  • header

  • fail

ignore

String

oauthProfile (security)

The OAuth profile to use for authenticating the incoming requests. The profile is enforced by the consumer component servicing the requests, and the route fails to start when that component cannot enforce one.

String

postmanApiKey (security)

The Postman API key used to fetch the collection from the Postman cloud. This credential authenticates against Postman itself and is never sent to the API the collection describes.

String

postmanApiKeyHeader (security)

The HTTP header used to send the Postman API key when fetching a collection.

X-Api-Key

String

resolveVariablesFromProperties (security)

Whether a \{{variable}} placeholder that neither the collection nor the variables option defines is resolved from Camel properties, which by default also cover JVM system properties and OS environment variables. With auto, this is done for a collection read from the classpath or the file system, and not for one fetched from the Postman cloud, over HTTP or through any other resource scheme, because whoever edits or serves such a collection could otherwise copy those values into an outgoing request. Use enabled or disabled to decide explicitly for any source.

Enum values:

  • auto

  • enabled

  • disabled

auto

String

sslContextParameters (security)

The TLS configuration used when fetching a collection from the Postman cloud, and set on the component that performs the requests when this endpoint creates it, as one already in the Camel context is not changed. If not set, see useGlobalSslContextParameters.

SSLContextParameters

useGlobalSslContextParameters (security)

Whether to use the global SSL context parameters of the Camel context when sslContextParameters is not set, when fetching a collection from the Postman cloud and for the component that performs the requests when this endpoint creates it.

false

boolean

postmanApiUrl (security (advanced))

The base URL of the Postman API used to fetch collections. Must use https, except for localhost, because plain http would send the Postman API key in clear text.

https://api.getpostman.com

String

Endpoint Options

The REST Postman endpoint is configured using URI syntax:

rest-postman:collectionSource#requestId

With the following path and query parameters:

Path Parameters

Name Description Default Type

collectionSource (common)

The Postman Collection to use. Either a resource URI of a Collection v2.1 JSON document (classpath:, file: or http:), where a name without a scheme is loaded from the classpath, or the uid of a collection to fetch from the Postman cloud, which requires postmanApiKey. Default value notice: By default loads the postman-collection.json file.

postman-collection.json

String

requestId (producer)

The request to invoke: its id in the collection, its slugified name such as getUserById, or its folder qualified slug such as users/getUserById. A folder slug selects every request in that folder, and leaving it out selects the whole collection. Append a slash to force a folder match when a request and a folder share a name. A consumer serves only the selected requests.

String

Query Parameters

Name Description Default Type

basePath (common)

The base path of the API, for example /v2, in front of the path of every request, and the path the consumer serves the requests under. If not set, the context path of the REST configuration is used, or else the path that the host of the request URL carries, such as /v1 when \{{baseUrl}} is https://api.example.com/v1.

String

collectionSourceType (common)

How to interpret collectionSource. With auto, a bare collection UUID or {ownerId}-{uuid} is fetched from the Postman cloud and anything else is resolved as a resource (classpath:, file:, http:). Use resource or cloud to decide explicitly.

Enum values:

  • auto

  • resource

  • cloud

auto

String

variables (common)

Values for the \{{variable}} placeholders used in the collection. These override the variables declared by the collection and its folders. This is a multi-value option with prefix: variable.

Map

failOnUnresolvedVariable (common (advanced))

Whether to fail when a \{{variable}} placeholder used by a selected request cannot be resolved. When false the placeholder is left as-is in headers and bodies, while one left in the URL, the query parameters, Accept or Content-Type fails anyway.

false

boolean

apiContextPath (consumer)

The path, below the base path, on which the consumer serves the collection document as JSON, for example /postman.json. The auth blocks are removed from the document and the values of secret variables are replaced. If not set, the document is not served.

String

clientRequestValidation (consumer)

Whether the consumer validates the incoming requests. A Postman collection has no schemas, so this is a best-effort check: the headers the request declares, the query parameters that have a value in the collection, a body when the collection has one, and the media types. It is also enabled by clientRequestValidation of the REST configuration.

false

boolean

missingRequest (consumer)

What the consumer does with a request of the collection that has no route consuming from the direct endpoint named after the request id, such as direct:getUserById. With fail the route does not start, with ignore a warning is logged and such a request goes on to the route of this endpoint as is, and with mock it is answered with a saved example response of the collection, or else a file found by mockIncludePattern. If not set, it is mock when the Camel profile is dev, and fail otherwise.

Enum values:

  • fail

  • ignore

  • mock

fail

String

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

consumerComponentName (consumer (advanced))

Name of the Camel component that serves the HTTP requests, which must implement the RestOpenApiConsumerFactory SPI, as platform-http does. If not set, a component with that capability already in the Camel context is used, or else platform-http.

String

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

mockIncludePattern (consumer (advanced))

Comma separated Ant-style patterns of the files that missingRequest=mock answers from, for a request without a saved example response in the collection. A file is used when its path without the extension ends with the request path, such as camel-mock/pets/1.json for GET /pets/1.

classpath:camel-mock/**

String

requestFilter (consumer (advanced))

Filters which requests of the collection are used, by the consumer and the producer, as comma separated Ant-style patterns matched against the folder qualified slug of the request, such as users/getUserById. Prefix a pattern with ! to exclude; with only exclusions, every other request is kept.

String

host (producer)

The scheme, host name and port to send the requests to, in the form http[s]://hostname[:port]. If set, it replaces the host of every request URL in the collection. If not set, the host comes from the request URL, then from the REST configuration, and for a collection loaded over HTTP from the address it was loaded from.

String

runFailFast (producer)

When the endpoint runs more than one request, that is when it selects a folder or the whole collection, whether to stop and fail on the first request that fails. When false every request is attempted and the failure is recorded in its result.

true

boolean

componentName (producer (advanced))

Name of the Camel component that performs the HTTP requests, which must implement the RestProducerFactory SPI, as http, vertx-http, undertow and netty-http do. If not set, a component with that capability already in the Camel context or the registry is used, or else the first of http, vertx-http, undertow and netty-http on the classpath.

String

consumes (producer (advanced))

The media type accepted in the response, sent as the Accept HTTP header. If not set, the Accept header of the request in the collection is used, when it has one. A Postman collection does not describe responses, so there is nothing else to infer it from.

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

produces (producer (advanced))

The media type of the request body, sent as the Content-Type HTTP header. If not set, the Content-Type header of the request in the collection is used, or else a type inferred from its body mode, such as application/json for a raw JSON body.

String

queryParameterMode (producer (advanced))

How to treat the query parameters declared in the collection. With placeholder the parameter names are bound to message headers and the values in the collection are ignored as sample data. With literal the values in the collection are sent as-is.

Enum values:

  • placeholder

  • literal

placeholder

String

collectionCacheTtl (advanced)

How long, in milliseconds, a loaded collection stays in the cache of the component, so that endpoints over the same collection load it once. A negative value keeps it until the component stops. The collection is read when a producer or consumer is created, so a running endpoint does not pick up changes.

-1

long

connectTimeout (advanced)

Connection timeout in milliseconds when fetching a collection from the Postman cloud.

15000

long

requestTimeout (advanced)

Request timeout in milliseconds when fetching a collection from the Postman cloud.

30000

long

collectionAuth (security)

What to do with the auth block the collection declares for the target API. With ignore the block is not applied, and a warning names the type that was found. With header the basic, bearer and apikey types are applied as a static header or query parameter, and any other type fails at startup rather than silently sending no credential. With fail any auth block other than noauth is rejected.

Enum values:

  • ignore

  • header

  • fail

ignore

String

oauthProfile (security)

The OAuth profile to use for authenticating the incoming requests. The profile is enforced by the consumer component servicing the requests, and the route fails to start when that component cannot enforce one.

String

postmanApiKey (security)

The Postman API key used to fetch the collection from the Postman cloud. This credential authenticates against Postman itself and is never sent to the API the collection describes.

String

postmanApiKeyHeader (security)

The HTTP header used to send the Postman API key when fetching a collection.

X-Api-Key

String

resolveVariablesFromProperties (security)

Whether a \{{variable}} placeholder that neither the collection nor the variables option defines is resolved from Camel properties, which by default also cover JVM system properties and OS environment variables. With auto, this is done for a collection read from the classpath or the file system, and not for one fetched from the Postman cloud, over HTTP or through any other resource scheme, because whoever edits or serves such a collection could otherwise copy those values into an outgoing request. Use enabled or disabled to decide explicitly for any source.

Enum values:

  • auto

  • enabled

  • disabled

auto

String

sslContextParameters (security)

The TLS configuration used when fetching a collection from the Postman cloud, and set on the component that performs the requests when this endpoint creates it, as one already in the Camel context is not changed. If not set, see useGlobalSslContextParameters.

SSLContextParameters

useGlobalSslContextParameters (security)

Whether to use the global SSL context parameters of the Camel context when sslContextParameters is not set, when fetching a collection from the Postman cloud and for the component that performs the requests when this endpoint creates it.

false

boolean

postmanApiUrl (security (advanced))

The base URL of the Postman API used to fetch collections. Must use https, except for localhost, because plain http would send the Postman API key in clear text.

https://api.getpostman.com

String

Message Headers

The REST Postman component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelRestPostmanRequestId (common)

Constant: REQUEST_ID

The id of the Postman request being invoked or serviced: its slugified name, qualified with its folders when the name is not unique in the collection.

String

CamelRestPostmanRequestName (common)

Constant: REQUEST_NAME

The name of the Postman request, as written in the collection.

String

CamelRestPostmanFolderPath (common)

Constant: FOLDER_PATH

The folder path of the Postman request invoked by the producer, with the folder names separated by a slash. Not set for a request at the top level of the collection.

String

CamelRestPostmanRequestCount (common)

Constant: REQUEST_COUNT

The number of requests executed when running a folder or a whole collection.

Integer

CamelRestPostmanFailedCount (common)

Constant: FAILED_COUNT

The number of requests that failed when running a folder or a whole collection. It is above 0 only with runFailFast disabled, as otherwise the first failure fails the exchange.

Integer

Message Body

The message body at each side of the REST Postman component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

stream, bytes, null, map or file

The request body as the HTTP consumer gives it (platform-http by default), null for a request without a body. It is handed to the direct route of the matched request (direct:<requestId>); the route of this endpoint then has the body that route left, or the saved example as a String with missingRequest=mock.

Not known when consumerComponentName is set.

Consumer reply

null, text, bytes or stream

The response body as the HTTP consumer writes it: text, bytes, a stream or no body. A Map or a List fails: marshal it first.

Not known when consumerComponentName is set.

Producer input

null, text, bytes, stream or file

For a single request, the body sent, by the http component by default: text, bytes, a stream or a file. A Map, a List or a number fails: marshal it first. A folder or the whole collection (no requestId) sends the bodies written in the collection and ignores the message body.

Not known when componentName is set.

Producer output

stream, bytes, null or list

For a single request, the response body as the http component gives it: the stream cache, or null for a response without a body. For a folder or the whole collection (no requestId), a List of PostmanRunResult, one per request, with its status and response body.

Not known when componentName is set.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Identifying requests

A Postman item has a human readable name rather than an operation id, so this component slugifies it: Get Pet By Id becomes getPetById. When two requests slugify to the same thing, both are addressed by their folder qualified id instead, such as pets/get and users/get, and using the bare get is an error that lists the alternatives.

item.id is also accepted when the collection records one. Note that it is optional in the v2.1 schema, and Postman’s exporter strips auto-generated item ids, so an exported collection.json usually has none. Collections fetched from the Postman cloud do.

Because the common case is to address a request by its slugified name, renaming a request in the Postman UI changes its id and will break routes bound to it.

Invoking a single request

  • Java

  • YAML

from("direct:start")
    .to("rest-postman:petstore.json#getPetById");
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: "rest-postman:petstore.json#getPetById"

The message body and headers of the exchange are what is sent. The collection supplies the method, the URL, and any headers the message does not already carry; the body written in the collection is treated as sample data and is not sent.

Path parameters written as :petId become {petId} placeholders resolved per exchange from the message header of the same name, falling back to the value declared in url.variable. Query parameters are bound to message headers in the same way and are dropped when unresolved. Set queryParameterMode=literal to send the values written in the collection instead.

Running a folder or a whole collection

Naming a folder, or naming nothing at all, runs every request in turn, in the manner of Postman’s collection runner:

  • Java

  • YAML

from("direct:smokeTest")
    .to("rest-postman:petstore.json#pets")    // every request in the Pets folder
    .to("rest-postman:petstore.json");        // every request in the collection
- route:
    from:
      uri: direct:smokeTest
      steps:
        # every request in the Pets folder
        - to:
            uri: "rest-postman:petstore.json#pets"
        # every request in the collection
        - to:
            uri: rest-postman:petstore.json

Because one exchange body cannot stand in for many different requests, each request sends the body and headers written in the collection. raw, graphql and urlencoded bodies are reconstructed; formdata and file bodies cannot be, and are skipped with a warning. The file body mode is never read from disk, as it records a path on the machine of whoever authored the collection.

The message body becomes a List of PostmanRunResult, one per request, each carrying the request id, method, URI, status code, response body, headers and any failure. The headers CamelRestPostmanRequestCount and CamelRestPostmanFailedCount summarise the run.

By default the run stops and fails on the first request that fails. Set runFailFast=false to attempt every request and record the failures in their results instead:

  • Java

  • YAML

from("timer:smoke?period=60000")
    .to("rest-postman:petstore.json?runFailFast=false")
    .split(body())
        .filter(simple("${body.success} == false"))
        .to("log:failures");
- route:
    from:
      uri: timer:smoke
      parameters:
        period: 60000
      steps:
        - to:
            uri: rest-postman:petstore.json
            parameters:
              runFailFast: false
        - split:
            expression:
              simple:
                expression: "${body}"
            steps:
              - filter:
                  expression:
                    simple:
                      expression: "${body.success} == false"
                  steps:
                    - to:
                        uri: log:failures

Contract-first consumer

Pointing a route’s from at a collection serves its requests over HTTP, dispatching each one to a route consuming from direct:<requestId>:

  • Java

  • YAML

from("rest-postman:petstore.json")
    .to("direct:dummy");

from("direct:getPetById")
    .setBody(constant("{ \"id\": 42 }"));
- route:
    from:
      uri: rest-postman:petstore.json
      steps:
        - to:
            uri: direct:dummy
- route:
    from:
      uri: direct:getPetById
      steps:
        - setBody:
            expression:
              constant:
                expression: "{ \"id\": 42 }"

Use a folder id to serve only part of a collection, and requestFilter to include or exclude requests by Ant-style patterns over their folder qualified ids.

Because a collection does not describe a base path, the split between base path and route path is inferred from what {{baseUrl}} expands to. Set basePath explicitly to control the context path the consumer serves on.

missingRequest decides what happens when a request has no corresponding route: fail (the default) refuses to start, ignore warns, and mock returns a mocked response. Mock responses are taken from the collection’s own saved example responses where there are any, which is the one place a collection is richer than an OpenAPI specification, and fall back to files matched by mockIncludePattern.

If two requests share an HTTP method and path, which is common when a collection keeps a success and an error variant of the same call, the consumer fails at startup rather than letting one silently shadow the other. Use requestFilter to choose between them.

Variables

{{variable}} placeholders are resolved from the collection’s own variable arrays, with folder scopes overriding the collection scope, then from the endpoint’s variables option, then, for a collection read from the classpath or the file system, from Camel property placeholders:

  • Java

  • YAML

from("direct:start")
    .to("rest-postman:petstore.json#getPetById?variable.baseUrl=https://staging.example.com/v3");
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: "rest-postman:petstore.json#getPetById"
            parameters:
              variable.baseUrl: https://staging.example.com/v3

Postman environment files are not supported. Unresolved placeholders are left as they are unless failOnUnresolvedVariable=true. The exception is one left in the host of the URL, a query parameter name, or the Accept or Content-Type header of a request: these become options of the delegate endpoint, where Camel would resolve the placeholder from its properties, so the producer fails to start instead.

A collection fetched from the Postman cloud is editable by anyone with access to the Postman workspace, and one fetched over HTTP by whoever serves it. Camel properties by default also cover JVM system properties and OS environment variables, so resolving such a collection’s placeholders from them would let its content copy any of those values into an outgoing request. Its placeholders are therefore not resolved from Camel properties: only classpath: and file: sources, and names without a scheme, are. Pass a property to such a collection explicitly in the endpoint URI, or set resolveVariablesFromProperties=enabled if you trust its content as much as your own configuration (disabled turns the lookup off for a local collection too; the default, auto, decides by source):

  • Java

  • YAML

from("direct:start")
    .to("rest-postman:12ece9e1-2abf-4edc-8e34-de66e74114d2#getPetById?postmanApiKey={{postman.apiKey}}"
        + "&variable.apiToken={{petstore.token}}");
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: "rest-postman:12ece9e1-2abf-4edc-8e34-de66e74114d2#getPetById"
            parameters:
              postmanApiKey: "{{postman.apiKey}}"
              variable.apiToken: "{{petstore.token}}"

A placeholder name written in the prefix:value form of a Camel property placeholder function — {{env:HOME}}, {{sys:user.home}}, {{bean:foo}} and the vault functions among them — is never resolved from Camel properties, whatever the source. Supply such values through the variables option instead.

Pre-request and test scripts in the collection’s event blocks are never parsed or executed.

Security

Two different credentials

There are two unrelated credentials in play, and the option names keep them apart:

postmanApiKey

authenticates against Postman itself, in order to download a collection from the Postman cloud. It is sent only to postmanApiUrl, and never to the API that the collection describes.

the collection’s own auth block

authenticates against the API the collection describes. It is governed by the collectionAuth option.

Fetching a collection from the Postman cloud

  • Java

  • YAML

from("direct:start")
    .to("rest-postman:12ece9e1-2abf-4edc-8e34-de66e74114d2#getPetById?postmanApiKey=PMAK-xxxx");
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: "rest-postman:12ece9e1-2abf-4edc-8e34-de66e74114d2#getPetById"
            parameters:
              postmanApiKey: PMAK-xxxx

Prefer resolving the key from a vault or a property placeholder over writing it in the URI. Redirects from postmanApiUrl are rejected rather than followed, because following one would send the key to the redirect target, and postmanApiUrl must use HTTPS unless it names a loopback host.

Applying the collection’s auth block

collectionAuth defaults to ignore: the block is not applied, and a warning names the type that was found. This is deliberate, because the values in a collection’s auth block are usually unresolved {{placeholders}}, and silently attaching a credential found in a configuration file to outbound requests is surprising.

Set collectionAuth=header to apply it. The basic, bearer and apikey types are reproduced as a static header or query parameter. The types that require per-request signing or a token exchange — awsv4, digest, hawk, edgegrid, ntlm, oauth1 and oauth2 — fail at startup rather than silently sending no credential; configure those on the delegate HTTP component instead. collectionAuth=fail rejects any auth block at all.

On the consumer side the collection’s auth block describes what a client must present, and is not enforced. Use oauthProfile, or the delegate consumer component’s own authentication, for that.

Serving the collection document

When apiContextPath is set, the collection is served on that path with the credentials removed or masked with ***. This redaction is unconditional:

  • every auth block is removed

  • the value of every variable of type secret is masked, and so is the value of any other variable whose name marks a credential, such as apiKey, password or accessToken

  • the value of a header whose name marks a credential is masked, in the requests and in the example responses: for example Authorization, Proxy-Authorization, x-api-key, api-key, Cookie, Set-Cookie and any header whose name contains token, password or secret. The same applies to the urlencoded and formdata body fields.

  • the value of every cookie of an example response is masked

  • in a URL, the password of the userinfo (https://user:password@host) and the value of a query parameter whose name marks a credential (such as api_key, apikey, token, access_token, password or secret) are masked, in the raw URL as well as in the host and query parts of a structured URL, and in a variable that holds a URL

A name marks a credential when Camel treats it as sensitive (see SensitiveUtils.isSensitiveHeader, which also covers names such as user and clientId), or when it contains token, password or secret.

A value that is only a Postman variable reference, such as {{apiKey}} or Bearer {{token}}, is a placeholder and is served as it is, so a client can see which variable to provide. The variable it refers to is masked where the collection defines it, when it holds a literal value.