# Twirp RPC — Artillery's `rpc-twirp-with-custom-function`, natively.
#
# Twirp speaks plain HTTP: POST to /twirp/<pkg.Service>/<Method> with a JSON (or
# protobuf) body. loadr's JSON body sets `Content-Type: application/json`, which
# is exactly Twirp's JSON mode — so a Twirp call is just an HTTP request. (For
# protobuf mode, send `body: { file: req.bin }` with a protobuf Content-Type.)
#
#   loadr run examples/43-twirp.yaml
name: twirp
description: Twirp RPC over HTTP/JSON — no codegen, just requests

defaults:
  http:
    base_url: https://rpc.example.com

scenarios:
  haberdasher:
    executor: constant-vus
    vus: 10
    duration: 30s
    flow:
      - request:
          name: MakeHat
          method: POST
          url: /twirp/twitch.twirp.example.haberdasher.Haberdasher/MakeHat
          body: { json: { inches: 12 } }
          extract:
            - { type: jsonpath, name: color, expression: "$.color" }
          checks:
            - { type: status, equals: 200 }
            - { type: jsonpath, expression: "$.size", equals: 12 }
      - request:
          name: ListHats
          method: POST
          url: /twirp/twitch.twirp.example.haberdasher.Haberdasher/ListHats
          body: { json: { limit: 20 } }
          checks:
            - { type: status, equals: 200 }

thresholds:
  checks: [ "rate>0.99" ]
  http_req_duration: [ "p(95)<400" ]
