Skip to content

Add a command to send requests to hosted endpoints - #29

Merged
miqui merged 3 commits into
mainfrom
endpoints-request
Nov 18, 2026
Merged

miqui merged 3 commits into
mainfrom
endpoints-request

Conversation

@miqui

@miqui miqui commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4

Summary

  • adapt endpoints request ID [PATH] looks up the endpoint's URL, sends one request to the hosted application, and writes the response body to stdout as it arrives. SSE streams work with no special handling.
  • -X sets the method, -H "Name: value" adds application headers (repeatable), and -d sends a body (inline, @file, or - for stdin). These letters match curl's.
  • --token TOKEN uses an existing endpoint token. --new-token creates one through POST /v1/ingresses/{id}/access-tokens for the resolved ID (not the prefix) and uses it. The two flags conflict.
  • The path defaults to /, may include a query, and is appended to the endpoint URL the way the guide builds ${ENDPOINT_URL}events. A path with a host, //, \ or # is refused before any request is sent.
  • A non-2xx status prints the body, then exits 1. For a redirect, the error names the Location.
  • Ctrl-C exits 130 at any point, including while a -d body is read from stdin, a device or a FIFO (on a blocking worker the runtime doesn't wait for), and while stdout is blocked (tokio's async stdout).

Credential isolation

  • The application request is built without Api::request(), so it never carries the Platform Authorization or X-Organization-Id. Platform credentials are used only for the endpoint lookup and token creation.
  • The only credential the application receives is the endpoint token in X-Adapt-Authorization, marked sensitive. -H can't set that header. An Authorization header passed with -H reaches the application unchanged.
  • -H is parsed by the command rather than clap, so an error never repeats a rejected header value, which could be a credential. Transport and body errors omit the request URL, which could carry one in its query.
  • Redirects are never followed. The endpoint URL from Platform must pass the existing HTTPS/loopback check, and the final URL must keep the endpoint's origin.
  • Application errors don't go through ensure_success, so an app's 401 isn't reported as "run adapt auth login".

Changes beyond endpoints request

  • input::data reads inline, @file or stdin bytes. input::json now uses it.
  • Ctrl-C during endpoints request exits 130 without printing "Remote executions continue…", since nothing remote is left running.

Docs

docs/cli-reference.md gets an Endpoint requests section with equivalents for the three curl examples in the published Endpoints guide, and lists the command in the table. The bundled skill is updated.

Testing

  • tests/endpoint_request/mod.rs has 13 tests against a mock Platform and a separate mock application:
    • An SSE response with no Content-Length: the first event must reach stdout while the application holds the stream open. When I made the code buffer the whole body, this test failed in about 10 seconds instead of hanging.
    • --new-token with an ID prefix, a POST body, and an application Authorization header. Then --token against an endpoint URL with a path prefix. Every application request is checked for the absence of Platform credentials.
    • A 404 prints its body and exits 1 without a sign-in hint. A 302 isn't followed and its Location is reported.
    • Rejected paths, the reserved X-Adapt-Authorization header, a malformed header, and --token with --new-token.
    • Rejected headers never appear in error output, and a connection error doesn't print a credential from the URL's query.
    • Bodies from -, @-, a file and @/dev/stdin arrive byte for byte (including NUL and invalid UTF-8) with no added Content-Type. A missing file and one over 16 MiB are reported, and the application request is never sent.
    • Ctrl-C exits 130 while a body is read from -, @-, @/dev/stdin, or a FIFO (both while opening it and while reading it), and while stdout is full. With blocking I/O on the async thread, the stdin and stdout tests failed instead of hanging.
  • I also ran it against a local Platform with INGRESS_DOMAIN=sandbox.test:
    • Lookup by ID prefix and --new-token succeeded with an API key, and the CLI built https://ID.sandbox.test/events?since=1. The final request stopped at DNS, since that domain has no DNS or TLS locally.
    • Through the proxy (curl with a Host header): no token or a wrong token got 401, and a token from adapt endpoints token passed the auth check and reached 404 Endpoint is not bound.
    • A local sandbox failed to start, so the application hop wasn't exercised against a live app.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test --locked pass.

Known limits

  • The command signs in to Platform even for public endpoints, because it looks up the URL through the API.
  • A stream that is silent for longer than --timeout (default 60s) ends with exit 1. Platform's proxy also closes SSE streams after 60 seconds of inactivity.
  • The Endpoints guide in adapt/platform isn't edited here. Its source wasn't accessible to me, so its curl examples can be switched to these commands in the docs PR.

🤖 Generated with Claude Code

`adapt endpoints request ID [PATH]` looks up the endpoint's URL, sends one
request to the hosted application, and streams the response body to stdout.
It supports -X, -H, -d, an explicit --token, or --new-token to create one.

Platform credentials only look up the endpoint and create a token. The
application receives the caller's headers and, at most, the endpoint token in
X-Adapt-Authorization. Redirects are not followed. A non-2xx status prints
the body, then exits 1.

Closes #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@the-adaptile the-adaptile Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confidence Score: 4/5

Summary

Adds streamed endpoint requests with isolated endpoint authentication and cancellable body input. Code risk appears low after local formatting, clippy, 112 tests, and loopback probes; live application integration and non-Linux execution remain unverified.

Deployed verification not applicable: adapt/platform-cli is outside the adapt/adapt and adapt/platform preview pilot; no webhook was sent.

Important Files Changed

File Changes
src/commands.rs Endpoint resolution, isolated requests, token creation, streaming, diagnostic redaction, and interruptible body reads.
src/cli.rs Endpoint request arguments and deferred header validation to avoid credential echoes.
src/input.rs Shared byte-input helper and sanitized application-header validation.
src/main.rs Endpoint-specific Ctrl-C messaging.
tests/endpoint_request/mod.rs Streaming, authentication, redirects, binary bodies, input errors, diagnostic privacy, and cancellation regression coverage.
tests/cli.rs Registers endpoint request integration tests.
docs/cli-reference.md Documents endpoint requests, authentication, streaming, timeouts, cancellation, and exit behavior.
skills/adapt/SKILL.md Adds endpoint request examples and credential-isolation guidance.

Run info

Field ID
Agent 0d6ccd7e-b62f-4075-a561-199d1a7b1bf0
Automation ec14e69d-634f-4af0-a6dd-27aa06a1f6b3
Run 07d727f5-b6b3-4978-b6c6-e4da48d2d783

Reviewed: ce8604b-cbc9332 · ↻ Re-run review

Comment thread src/input.rs Resolved
Comment thread src/commands.rs Resolved
Comment thread src/commands.rs Resolved
- Parse -H in the command instead of clap, whose errors repeat the rejected
  value. A forbidden X-Adapt-Authorization header or a malformed header no
  longer prints a credential; these now exit 1.
- Strip request URLs from transport and body errors with without_url(), as
  Api does, so a credential in the query is never printed.
- Read a `-d -` body and write the response with tokio's async stdin and
  stdout, so Ctrl-C exits 130 while waiting for input or a full stdout pipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/commands.rs Resolved
Read -d bodies on a blocking worker for all sources, not only stdin. An
@file path can also block on a FIFO or device; runtime shutdown does not
wait for the worker, so Ctrl-C still exits 130 while opening or reading.

Tests cover byte-exact bodies from -, @-, a file and /dev/stdin, missing
and oversized files, and Ctrl-C during @-, /dev/stdin and FIFO open/read.
The Ctrl-C helper now reaps the child it kills on timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@miqui
miqui merged commit ff76bfb into main Nov 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add HTTP and streaming requests to hosted endpoints

1 participant