diff --git a/packages/oc-spec-site/src/components/Content.jsx b/packages/oc-spec-site/src/components/Content.jsx
index c53a6b34..1b5fbe54 100644
--- a/packages/oc-spec-site/src/components/Content.jsx
+++ b/packages/oc-spec-site/src/components/Content.jsx
@@ -335,16 +335,18 @@ runtime:
- name: userId
value: "123"
scripts:
- - type: before-request
+ - type: grpc:before-call-start
code: |
- bru.setVar('timestamp', Date.now());
- - type: after-response
+ bru.grpc.request.metadata.upsert('x-api-key', {{apikey}})
+ - type: grpc:before-message-send
code: |
- bru.setVar('user', res.body);
- assertions:
- - expression: res.status
- operator: equals
- value: "0"
+ bru.setVar('sentCount', (bru.getVar('sentCount') || 0) + 1);
+ - type: grpc:after-message-receive
+ code: |
+ bru.setVar('receivedCount', bru.grpc.response.messages.count());
+ - type: grpc:after-call-end
+ code: |
+ bru.setVar('user', bru.grpc.response.messages.get(0).data.value);
auth:
type: bearer
token: "{{authToken}}"`;
@@ -407,7 +409,7 @@ runtime:
Properties
diff --git a/packages/oc-spec-site/src/components/sections/ScriptsLifecycle.jsx b/packages/oc-spec-site/src/components/sections/ScriptsLifecycle.jsx
index 4b10cee1..cf652e92 100644
--- a/packages/oc-spec-site/src/components/sections/ScriptsLifecycle.jsx
+++ b/packages/oc-spec-site/src/components/sections/ScriptsLifecycle.jsx
@@ -20,12 +20,24 @@ function ScriptsLifecycle({ schema }) {
code: "// Extract auth token\nconst token = res.body.token;\nbru.setVar('authToken', token);"
},
{
- type: "tests",
- code: "// Test response\ntest('Status is 200', () => {\n expect(res.status).to.equal(200);\n});"
+ type: "grpc:before-call-start",
+ code: "// set a metadata value before the call is opened.\nbru.grpc.request.metadata.upsert('x-api-key', {{apikey}});"
+ },
+ {
+ type: "grpc:before-message-send",
+ code: "// Update a var with the sent count.\nbru.setVar('sentCount', (bru.getVar('sentCount') || 0) + 1);"
+ },
+ {
+ type: "grpc:after-message-receive",
+ code: "// Update a var with the received count.\nbru.setVar('receivedCount', bru.grpc.response.messages.count());"
+ },
+ {
+ type: "grpc:after-call-end",
+ code: "// Extract a value from a message.\nbru.setVar('user', bru.grpc.response.messages.get(0).data.value);"
},
{
- type: "hooks",
- code: "// Custom lifecycle hooks"
+ type: "tests",
+ code: "// Test response\ntest('Status is 200', () => {\n expect(res.status).to.equal(200);\n});"
}
];
@@ -45,18 +57,30 @@ function ScriptsLifecycle({ schema }) {
- before-request - Executed before the request is sent. Use for setting up authentication, generating dynamic values, etc.
- after-response - Executed after receiving the response. Use for extracting values, setting variables, etc.
+ - grpc:before-call-start - Executed before the call is opened. Use for setting metadata, generating dynamic values, etc.
+ - grpc:before-message-send - Executed before each message is sent, once per message on client-streaming and bidi-streaming calls.
+ - grpc:after-message-receive - Executed after each message is received, once per message on server-streaming and bidi-streaming calls.
+ - grpc:after-call-end - Executed after the call ends, whether it completed or errored. Use for extracting values, setting variables, etc.
- tests - Run test assertions against the response
- - hooks - Custom lifecycle hooks
-
+
Execution Lifecycle
+ HTTP & GraphQL
- Before-Request - Executed before the request is sent
- Request Sent - The actual HTTP request is made
- After-Response - Executed after receiving the response
- Tests - Run test assertions against the response
-
+ gRPC
+
+ - gRPC:Before-Call-Start - Executed before a gRPC call is opened
+ - Call Established - The channel is opened and the method is invoked
+ - gRPC:Before-Message-Send - Executed before each outgoing message on a gRPC call
+ - gRPC:After-Message-Receive - Executed after each incoming message on a gRPC call
+ - gRPC:After-Call-End - Executed once a gRPC call ends
+
+
Example