Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/oc-spec-site/src/components/Content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"`;
Expand Down Expand Up @@ -407,7 +409,7 @@ runtime:
<h3 className={typography.heading.h3}>Properties</h3>
<PropertyTable
properties={grpcRequestRuntime.properties}
order={['variables', 'scripts', 'assertions', 'auth']}
order={['variables', 'scripts', 'auth']}
required={grpcRequestRuntime.required}
/>

Expand Down
38 changes: 31 additions & 7 deletions packages/oc-spec-site/src/components/sections/ScriptsLifecycle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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});"
}
];

Expand All @@ -45,18 +57,30 @@ function ScriptsLifecycle({ schema }) {
<ul className={`list-disc list-inside space-y-2 ${spacing.element} ${typography.body.default}`}>
<li><strong>before-request</strong> - Executed before the request is sent. Use for setting up authentication, generating dynamic values, etc.</li>
<li><strong>after-response</strong> - Executed after receiving the response. Use for extracting values, setting variables, etc.</li>
<li><strong>grpc:before-call-start</strong> - Executed before the call is opened. Use for setting metadata, generating dynamic values, etc.</li>
<li><strong>grpc:before-message-send</strong> - Executed before each message is sent, once per message on client-streaming and bidi-streaming calls.</li>
<li><strong>grpc:after-message-receive</strong> - Executed after each message is received, once per message on server-streaming and bidi-streaming calls.</li>
<li><strong>grpc:after-call-end</strong> - Executed after the call ends, whether it completed or errored. Use for extracting values, setting variables, etc.</li>
<li><strong>tests</strong> - Run test assertions against the response</li>
<li><strong>hooks</strong> - Custom lifecycle hooks</li>
</ul>

<h3 className={`${typography.heading.h3} ${spacing.paragraph}`}>Execution Lifecycle</h3>
<p className={`${typography.body.small} ${spacing.paragraph}`}><strong>HTTP & GraphQL</strong></p>
<ol className={`list-decimal list-inside space-y-2 ${spacing.element} ${typography.body.default}`}>
<li><strong>Before-Request</strong> - Executed before the request is sent</li>
<li><strong>Request Sent</strong> - The actual HTTP request is made</li>
<li><strong>After-Response</strong> - Executed after receiving the response</li>
<li><strong>Tests</strong> - Run test assertions against the response</li>
</ol>

<p className={`${typography.body.small} ${spacing.paragraph}`}><strong>gRPC</strong></p>
<ol className={`list-decimal list-inside space-y-2 ${spacing.element} ${typography.body.default}`}>
<li><strong>gRPC:Before-Call-Start</strong> - Executed before a gRPC call is opened</li>
<li><strong>Call Established</strong> - The channel is opened and the method is invoked</li>
<li><strong>gRPC:Before-Message-Send</strong> - Executed before each outgoing message on a gRPC call</li>
<li><strong>gRPC:After-Message-Receive</strong> - Executed after each incoming message on a gRPC call</li>
<li><strong>gRPC:After-Call-End</strong> - Executed once a gRPC call ends</li>
</ol>

<h3 className={`${typography.heading.h3} ${spacing.paragraph}`}>Example</h3>
<CodeBlock code={convertToYaml(example)} language="yaml" />
</section>
Expand Down