Skip to content

Commit c96bb7d

Browse files
authored
Tutorial: 10-Orchestration (#2677)
* feat(dispatcher): add production mode support for error handling and extend URI validation tests - Introduced `productionRouter` in `DummyTestRouter` to enable production mode configuration. - Updated `DispatchingInterceptor` to adjust error messages in production mode. - Expanded `DispatchingInterceptorTest` with production-specific URI validation. * feat(tutorials): add orchestration example combining multiple backend calls - Introduced `10-Orchestration.yaml` to demonstrate creating an API that combines two backend calls. - Added cross-platform `membrane.sh` and `membrane.cmd` scripts to locate and execute the Membrane runtime.
1 parent 7b8f5d0 commit c96bb7d

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# yaml-language-server: $schema=https://www.membrane-api.io/v7.0.6.json
2+
#
3+
# Tutorial: Orchestration
4+
#
5+
# Shows how to create an API that combines two backend calls into one API.
6+
# 1) Fetch a book by id.
7+
# 2) Use the author key from the book payload to fetch the author.
8+
#
9+
# Try:
10+
# curl localhost:2000/books/OL29474405M
11+
# curl localhost:2000/books/OL26333978M
12+
13+
api:
14+
port: 2000
15+
path:
16+
uri: /books/{id}
17+
flow:
18+
- request:
19+
- call:
20+
url: https://openlibrary.org/books/${pathParam.id}.json
21+
- setProperty:
22+
name: title
23+
value: ${$.title}
24+
language: jsonpath
25+
- call:
26+
url: https://openlibrary.org${$.authors[0].key}.json
27+
language: jsonpath
28+
- template:
29+
contentType: application/json
30+
src: |
31+
{
32+
"title": "${property.title}",
33+
"author": "${fn.jsonPath('$.name')}"
34+
}
35+
- return:
36+
status: 200
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
setlocal EnableExtensions
3+
4+
set "SCRIPT_DIR=%~dp0"
5+
if "%SCRIPT_DIR:~-1%"=="\" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
6+
7+
set "dir=%SCRIPT_DIR%"
8+
9+
:search_up
10+
if exist "%dir%\LICENSE.txt" if exist "%dir%\scripts\run-membrane.cmd" goto found
11+
for %%A in ("%dir%\..") do set "next=%%~fA"
12+
if /I "%next%"=="%dir%" goto notfound
13+
set "dir=%next%"
14+
goto search_up
15+
16+
:found
17+
set "MEMBRANE_HOME=%dir%"
18+
set "MEMBRANE_CALLER_DIR=%SCRIPT_DIR%"
19+
call "%MEMBRANE_HOME%\scripts\run-membrane.cmd" %*
20+
exit /b %ERRORLEVEL%
21+
22+
:notfound
23+
>&2 echo Could not locate Membrane root. Ensure directory structure is correct.
24+
exit /b 1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
# Default: ./proxies.xml (next to this script); fallback -> $MEMBRANE_HOME/conf/proxies.xml
3+
# JAVA_OPTS: relative -D paths are auto-resolved against $MEMBRANE_HOME (absolute/URI unchanged).
4+
# Examples:
5+
# export JAVA_OPTS='-Dlog4j.configurationFile=examples/logging/access/log4j2_access.xml'
6+
# export JAVA_OPTS='-Dlog4j.configurationFile=/abs/path/log4j2.xml'
7+
8+
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
9+
10+
dir="$SCRIPT_DIR"
11+
while [ "$dir" != "/" ]; do
12+
if [ -f "$dir/LICENSE.txt" ] && [ -f "$dir/scripts/run-membrane.sh" ]; then
13+
export MEMBRANE_HOME="$dir"
14+
export MEMBRANE_CALLER_DIR="$SCRIPT_DIR"
15+
exec sh "$dir/scripts/run-membrane.sh" "$@"
16+
fi
17+
dir=$(dirname "$dir")
18+
done
19+
20+
echo "Could not locate Membrane root. Ensure directory structure is correct." >&2
21+
exit 1

0 commit comments

Comments
 (0)