>_ RESTERM
v1.18.2

examples Workflows and mocks

polling-retries.http

Polling and retries against mock sequences in the same file. Two requests fail on purpose.

start the local mock first

shell
resterm _examples/polling-retries.http

Run this from the root of a clone of the Resterm repository.

Editor
# Serve these mocks with `resterm mock _examples/polling-retries.http`, or open
# this file in the TUI and press `g Shift+M`.
# @const mock.base http://127.0.0.1:8080

### Job lifecycle
# Each X-Demo-Run value gets its own sequence cursor.
# @mock method=GET path=/jobs/{id} sequence=poll-demo sequence-key=header.X-Demo-Run
HTTP/1.1 202 Accepted
Content-Type: application/json

{"id":{{json.path.id}},"status":"pending"}
---
HTTP/1.1 202 Accepted
Content-Type: application/json

{"id":{{json.path.id}},"status":"pending"}
---
HTTP/1.1 200 OK
Content-Type: application/json

{"id":{{json.path.id}},"status":"completed"}

### Temporarily unavailable service
# @mock method=GET path=/unstable sequence=retry-demo sequence-key=header.X-Demo-Run
HTTP/1.1 503 Service Unavailable
Content-Type: application/json
Retry-After: 1

{"error":"service overloaded"}
---
HTTP/1.1 502 Bad Gateway
Content-Type: application/json

{"error":"upstream unavailable"}
---
HTTP/1.1 200 OK
Content-Type: application/json

{"status":"ok"}

### Poll until the job completes
# @name poll-job
# @poll every=250ms timeout=5s until=response.json().status == "completed"
GET {{mock.base}}/jobs/job_42
X-Demo-Run: {{$uuid}}

### Retry transient responses
# @name retry-transient
# @retry count=3
# @retry-when response.statusCode in [429, 502, 503]
# @retry-backoff exponential(100ms, 500ms) jitter=20%
GET {{mock.base}}/unstable
X-Demo-Run: {{$uuid}}

### Poll timeout (expected failure)
# Pinning the sequence to 202 keeps the job pending until @poll times out.
# @name poll-timeout
# @retry count=3
# @retry-when response.statusCode in [429, 502, 503]
# @retry-backoff exponential(100ms, 500ms) jitter=20%
# @poll every=250ms timeout=2s until=response.json().status == "completed"
GET {{mock.base}}/jobs/job_stuck
X-Demo-Run: {{$uuid}}
X-Resterm-Mock-Status: 202

### Exhaust retries (expected failure)
# Pinning the sequence to 503 prevents it from reaching the successful response.
# @name retry-exhausted
# @retry count=3
# @retry-when response.statusCode in [429, 502, 503]
# @retry-backoff exponential(100ms, 500ms) jitter=20%
GET {{mock.base}}/unstable
X-Demo-Run: {{$uuid}}
X-Resterm-Mock-Status: 503

_examples/polling-retries.http on GitHub

Polling and retries docs
Search

↑↓ moveEnter openEsc close

Help

These keys work like the ones in the TUI.

/
Search the docs (also Ctrl K)
j k
Scroll down and up
g g G
Jump to the top or the bottom
[ ]
Previous and next page
g d
Docs index
g h
Home page
t
Switch between dark and light
?
Show this help
Esc
Close a dialog