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 }) { - +

Execution Lifecycle

+

HTTP & GraphQL

  1. Before-Request - Executed before the request is sent
  2. Request Sent - The actual HTTP request is made
  3. After-Response - Executed after receiving the response
  4. Tests - Run test assertions against the response
- +

gRPC

+
    +
  1. gRPC:Before-Call-Start - Executed before a gRPC call is opened
  2. +
  3. Call Established - The channel is opened and the method is invoked
  4. +
  5. gRPC:Before-Message-Send - Executed before each outgoing message on a gRPC call
  6. +
  7. gRPC:After-Message-Receive - Executed after each incoming message on a gRPC call
  8. +
  9. gRPC:After-Call-End - Executed once a gRPC call ends
  10. +
+

Example