Request-Response Processing Mode
This document covers topics which are specific to Request-Response processing mode. Please read the introduction to scenario authoring to learn basics of scenario authoring.
Defining input and output from the Request - Response scenario
Unlike in the Streaming processing mode, there is no Schema Registry which would store data schemas - request and response schemas in our case. Still, the schema of the request and response ("input" and "output") need to be declared to Nussknacker; they are defined alongside the scenario (as the scenario property). The "language" used to define schemas is called JSON Schema. Nussknacker uses those schemas to understand how the request and response should look, assist you with hints and validate expressions you write.
Click kebab menu icon (three vertically aligned dots next to the scenario name) on the right panel and access the properties of the scenario to view or edit the input and output schemas of the scenario.
The same Input schema and Output schema (and the Slug) can also be edited directly in the request source node; changes made there are saved as the scenario properties.
When the request source uses a bodyless method (GET or DELETE), its input is declared by the node's Query parameters instead, so the node does not show Input schema.
Input schema and Query parameters open as a box listing the fields with their types, the way the Key-Value
Store node shows a namespace. Edit opens the table of fields in place: a name, a type (scalars, dates, an object
with its own fields, a list of any of these), whether the field is required, and under "More options" a
description, a default, whether null is accepted and a list of allowed values (enum). The JSON text is one toggle away. The
table edits the stored schema in place and keeps whatever it has no column for: constraints such as minLength
or pattern, root keywords and constructs it cannot express ($ref, oneOf, a map) are preserved; a field of
such a type is listed with a simplified type (Union, Map[String, T], Any) and its type can only be changed
as JSON. Query parameters offers scalars and lists of scalars only, as a query string carries nothing else.
A new scenario starts with {} as its input schema: any JSON body is accepted and #input is untyped, so a field
is read as #input["name"], without hints or validation (#input.name is a typing error on an untyped value).
The empty box says so and offers four ways to declare the fields: add them in the table, paste a JSON Schema, paste
an example message body and take the draft schema read off it (every field required, types from the values; adjust
it afterwards), or import an operation of an OpenAPI document. The import takes the document as text (OpenAPI 2 or
3, JSON or YAML: the service's /definition or /openapi.json, opened in a browser tab and copied; the Designer
never fetches a URL), lists its operations, and the chosen one fills the node's Method, Query parameters,
Input schema (its JSON request body, $refs inlined) and Output schema (its responses by status code, the
default entry from the default response or the first 2xx). Only references within the document
(#/components/...) are inlined: a document referring to a URL or a file is refused, and nothing it names is
fetched or read. A schema that refers back to itself is imported with the inner occurrence accepting any value, and
the dialog says so. The Slug stays as it is: it is this scenario's
endpoint, not the imported path. Path and header parameters have no place on the source and are listed as not
imported.
The output schema is a map from HTTP status code to that code's JSON Schema, with a required default entry used for any status code without its own schema:
{
"default": { "type": "object", "properties": { "name": { "type": "string" } } },
"404": { "type": "object", "properties": { "message": { "type": "string" } } }
}
A response sink is validated against - and its response is encoded with - the schema of its selected HTTP status code, falling back to default. The keys must be status codes supported by the HTTP status code sink parameter. The generated OpenAPI definition describes each status code with its own schema.
The Output schema opens as one box of fields per status code, the default entry first, each edited like the
Input schema (the table of fields, the JSON view, a pasted schema or an example message). Add a status code...
gives a code a schema of its own; Remove takes it away again, back to default. On the request source it sits
under Advanced parameters..., and the Properties dialog shows the same box. A response sink shows a Response schema
section with only the entry its HTTP status code is validated against: the code's own, or default with a note
that the code has none and a Define a schema specific to <code> button, which starts the code's entry as a copy of
default. The fields that the output schema defines for a response sink can be filled with the
Data Mapper.
Responses other than JSON
A response is JSON (application/json) unless its entry gives it another content type, such as an HTML page or plain
text. Each box of the Output schema has a content type: one of the usual ones offered (application/json,
text/html, text/plain, text/csv, application/xml), or any other typed in, such as text/javascript or
text/csv; header=present. The scenario validation rejects one that is not a media type, names a charset the runtime
does not have, or is multipart/... without a boundary parameter. It rejects text/event-stream too: the scenario
answers with one complete body, not a stream of events. An entry of another content type than JSON has no schema; it is
stored as a string schema with the JSON Schema contentMediaType keyword:
{
"default": { "type": "object", "properties": { "name": { "type": "string" } } },
"200": { "type": "string", "contentMediaType": "text/html" }
}
A response sink whose HTTP status code selects such an entry has a single Value parameter: a String, written as a
template (text with expressions inside #{...}) or as an expression; for text/html the template editor colours the
text as HTML. It is sent as it is, with that content type and, for a text type, charset=UTF-8. In the template
<p>Hello #{#UTIL.escapeHtml(#input.name)}</p>,
#UTIL.escapeHtml makes a value taken from the
request show as text instead of becoming part of the page. The generated OpenAPI definition lists the response under its
content type. Error responses of the scenario stay JSON.
Whatever the content type, the scenario answers once, with the whole body, when the request has been processed. When
several results reach response sinks, e.g. after a for-each or on two branches, a JSON or text response sends only the
first one. To answer with all of them, collect them into a list before the sink with collect, or give the status code
a content type of JSON lines: application/x-ndjson (or application/jsonl). Such an entry keeps a schema, the schema
of one record, so the response sink builds one record as for JSON, and every result becomes a line of the body, in the
order the results came; a for-each straight before the sink answers with one line per element. The Designer warns
about a response sink that more than one result can reach and that sends only the first one.
{
"default": {
"type": "object",
"properties": { "name": { "type": "string" } },
"contentMediaType": "application/x-ndjson"
}
}
Predefined variables
#input contains the request data.
#inputMeta currently contains only the incoming HTTP headers under #inputMeta.httpHeaders, a Map[String, String]. Header
names are lower-case. When a header occurs more than once, its values are joined with a comma and a space. The
authorization and x-nussknacker-api-token headers are not exposed.
Integrating scenario into the automation workflows
Click kebab menu icon and access the properties of the scenario to view the integration details of the scenario:
- the example
curlbased invocation - OpenAPI interface definition
- Swagger UI.
- Basic Auth credentials
The Integration section opens with an Access line saying who may call the scenario - anyone, the configured
Basic user, or a holder of a Nussknacker API token - and the example curl carries the matching credentials. See
Who may call the scenario for how to change it.
Note that on the first attempt to call Nussknacker scenario from Swagger UI you will be prompted to enter the credentials of your request - response scenario: the Basic Authentication credentials shown in the scenario Properties, or a Nussknacker API token when the scenario requires one. These are not your Nussknacker cloud credentials.
Who may call the scenario
The Access property of the scenario (in Properties, and under Advanced parameters of the Request node) decides who may call the deployed endpoint:
| Access | Who may call the scenario |
|---|---|
| Deployment default | Whatever the installation configures: its Basic user when one is set up, otherwise anyone. The behaviour from before the property existed |
| Open - no token required | Anyone who reaches the endpoint; no credentials are looked at |
| Nussknacker API token required | A Nussknacker API token whose owner may call this scenario (Scenario.Invoke on it or its category); the installation's Basic user still passes |
A change takes effect on the next deployment. A scenario requiring a token answers 401 to a call without
credentials or with an unknown, revoked or expired token, and 403 to a token whose owner may not call it. Its
OpenAPI definition and Swagger UI then need the same token, and the definition declares the token as its security
scheme, so a client generated from it or Swagger UI's Authorize takes it.
The installation may forbid open endpoints, and requiring a token needs access control in the Designer, which issues them.
A deployed Request - Response scenario can also be called by AI agents, as a tool of an MCP server hosted by Nussknacker - see MCP servers.
Calling a scenario from another scenario
To call a Request-Response scenario from another scenario, add its OpenAPI interface definition as an OpenAPI integration: copy the definition URL from the Integration section of the scenario's properties into the integration's Spec URL, and put the credentials the scenario is called with into the integration. The integration adds an enricher whose parameters are the fields of the scenario's input schema and whose result is typed by its output schema. When the called scenario's input or output schema changes, refresh the integration.
Do not call the scenario with the HTTP component and a URL typed in: its credentials would
be stored in the calling scenario, and the address depends on the installation - in Nussknacker Cloud it is the
instance's gateway, not localhost.
Scenario response in scenarios with split and for-each nodes
It may happen that the scenario contains parallel branches, following split node. This ifs common in situations when testing multiple 'hypothesis' is important and these 'hypothesis' are independent of each other. Performing this 'hypotheses testing' sequentially yields much higher response times than when the hypothesis are processed in parallel.
If parallel branches end with response nodes and more than one response is generated (e.g there is no filtering after split), the only response which is returned is the one which is generated first chronologically. There is no way to determine which one will be generated first. If all responses are important to you, you need to take additional measures - use the collect node to merge the branches and collect data records coming from individual branches into a list.
If you use for-each node and need to collect all the results into a list of values, use collect node.
Finally, if no response is generated (e.g. after filtering), an error is returned (in the future this behavior may change).
Request - Response specific components
Request
See this document for the details of the Request component.
Response
See this document for the details of the Response component.
Kafka service
Request-Response scenarios can also write messages to Kafka with the kafka service.
It becomes available when the liteRequestResponseKafka.jar component set is on the model classpath and the model configuration contains the kafka section (bootstrap servers, schema registry) - the same configuration as for the streaming Kafka components.
The parameters (Topic, Schema version, Key, Value) work exactly like in the streaming Kafka sink.
The record is sent to Kafka as part of handling the HTTP request and the service returns the metadata of the written record
(a record with the topic, partition, offset and timestamp fields), so the scenario can continue after the write - e.g. respond with the offset.
When the write fails, the whole request fails.
Delivery is at-least-once: a client retrying the HTTP request may produce duplicate records.
During scenario testing in Designer no records are sent to Kafka - the service only collects the value that would be written and returns stubbed metadata (partition, offset and timestamp set to -1).
Collect component
See here for description of the Collect component.
Scenario properties
Click kebab menu icon (three vertically aligned dots next to the scenario name) on the right panel and access the properties of the scenario.
Scenario properties explained
| Property name | Description |
|---|---|
| Name | Scenario name |
| Input schema | See Defining input and output from the Request - Response scenario for explanation |
| Output schema | See Defining input and output from the Request - Response scenario for explanation |
| Slug | Change slug to modify the url of your scenario and of its interface definition |
| Integration | See here |
| Access | Who may call the scenario |