Skip to content

x402 gated http api#295

Open
andrestielau wants to merge 4 commits into
mainfrom
spec/x402-gated-http-api
Open

x402 gated http api#295
andrestielau wants to merge 4 commits into
mainfrom
spec/x402-gated-http-api

Conversation

@andrestielau
Copy link
Copy Markdown
Contributor

Screen.recording.2026-05-13.12.30.03.PM.webm

This pull request introduces a new mock facilitator service and a narrated demo script to support and showcase the x402 v2 payment-gated HTTP API in the parser_gateway. It adds Docker build support for the mock facilitator, updates environment configuration for local development, and enhances integration test dependencies.

Key changes include:

New mock facilitator service:

  • Added parser/mock-facilitator crate to the workspace and created a corresponding Docker build (images/mock_facilitator/Containerfile, src/Cargo.toml, Makefile). [1] [2] [3]
  • Updated the parser_gateway Dockerfile to default to the local profile and use the mock facilitator URL for local development (images/parser_gateway/Containerfile).

Demo and developer tooling:

  • Introduced scripts/x402-demo.sh, a narrated, end-to-end Bash script that spins up the mock facilitator, parser gRPC server, and gateway, demonstrating various payment and error scenarios with commentary. This script aids both development and onboarding.

Integration test improvements:

  • Added reqwest and tokio as dev-dependencies to the integration test crate to support more advanced HTTP and async test scenarios (src/integration/Cargo.toml).

@andrestielau andrestielau self-assigned this May 13, 2026
Copilot AI review requested due to automatic review settings May 13, 2026 11:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a dev/test “mock facilitator” and wires the parser HTTP gateway with an x402 v2 payment-gated /visualsign/api/v2/parse endpoint, plus an end-to-end demo script and an integration test covering payment-required and paid flows.

Changes:

  • Introduces parser/mock-facilitator Axum service (workspace member) with a Docker image.
  • Refactors parser_gateway into a lib+bin layout, adds x402 config/env loading, and gates the new v2 parse route with x402 middleware.
  • Adds an end-to-end demo script and an integration test that boots mock facilitator + gRPC server + gateway.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/parser/mock-facilitator/src/main.rs Mock facilitator binary entrypoint + graceful shutdown.
src/parser/mock-facilitator/src/lib.rs Mock facilitator HTTP routes (/verify, /settle, /supported) + unit tests.
src/parser/mock-facilitator/Cargo.toml New crate manifest/deps for mock facilitator.
src/parser/mock-facilitator/build.rs Injects VERSION into build for runtime banner logging.
src/parser/gateway/src/x402_config.rs New env/profile-based x402 configuration + price-tag building.
src/parser/gateway/src/turnkey.rs Extracts Turnkey request/response envelope types + error helper.
src/parser/gateway/src/state.rs Extracts shared gateway app state types.
src/parser/gateway/src/main.rs Wires v1 open route + v2 x402-gated route and adds facilitator startup probe.
src/parser/gateway/src/lib.rs New library entrypoint exporting handlers/state/config modules.
src/parser/gateway/src/handlers/parse.rs Shared parse handler used by both v1 and v2 routes.
src/parser/gateway/src/handlers/mod.rs Handler module declarations.
src/parser/gateway/src/handlers/health.rs Health endpoint handler (gRPC health proxy).
src/parser/gateway/Cargo.toml Updates dependencies (axum 0.8, x402 crates, reqwest, etc.) and adds lib target.
src/integration/tests/x402_gateway_test.rs New end-to-end test booting three binaries and exercising v1/v2 behaviors.
src/integration/Cargo.toml Adds dev-deps needed for new HTTP-based integration test.
src/Cargo.toml Adds parser/mock-facilitator to workspace members.
src/Cargo.lock Locks new dependencies (x402 crates, reqwest 0.13, etc.).
scripts/x402-demo.sh Narrated demo script to run the full stack locally and walk through scenarios.
Makefile Adds mock_facilitator image build outputs and non-OCI build target.
images/parser_gateway/Containerfile Sets image ENV defaults for local x402 profile/facilitator URL.
images/mock_facilitator/Containerfile New Docker build for mock facilitator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/parser/gateway/src/main.rs Outdated
Comment thread images/parser_gateway/Containerfile Outdated
Comment thread src/parser/gateway/src/x402_config.rs Outdated
Comment on lines +234 to +250
fn parse_tags_json(json: &str) -> Result<Vec<PriceTagConfig>, ConfigError> {
let wire: Vec<PriceTagWire> =
serde_json::from_str(json).map_err(|e| ConfigError::JsonParse(e.to_string()))?;
wire.into_iter()
.map(|w| {
Ok(PriceTagConfig {
network: w.network,
asset: w.asset,
price_usd: Decimal::from_str(&w.price_usd).map_err(|e| {
ConfigError::Invalid {
var: "X402_PRICE_TAGS_JSON",
message: format!("priceUsd: {e}"),
}
})?,
pay_to: w.pay_to.into_pay_to()?,
scheme: w.scheme,
})
Comment thread src/parser/gateway/src/x402_config.rs Outdated
Comment thread scripts/x402-demo.sh Outdated
Comment on lines +37 to +44
chapter "Preflight" "Make sure we have everything we need before starting."

for tool in curl jq base64 cargo; do
if ! command -v "$tool" >/dev/null 2>&1; then
fail "missing tool: $tool"
fi
done
ok "curl, jq, base64, cargo all present"
Comment thread scripts/x402-demo.sh Outdated
Comment thread src/integration/tests/x402_gateway_test.rs Outdated
@andrestielau
Copy link
Copy Markdown
Contributor Author

@copilot address the comments, rebase, and resolve conflicts

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

@copilot address the comments, rebase, and resolve conflicts

Addressed the review comments in f71ec55 and 899cdbf (x402 config enum/validation, graceful x402 startup behavior, container/env defaults, demo portability checks, and test port-serialization fixes).
No UI changes were made in this PR, so there is no screenshot to share.

andrestielau and others added 4 commits May 14, 2026 22:25
Adds the design for a new POST /visualsign/api/v2/parse route with
x402-axum middleware, a mock_facilitator dev binary, and env+profile
config (local/payai/custom) with multi-tag support. Existing Turnkey
v1 endpoint and /health remain unprotected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Implemented a health-check handler in `health.rs` that proxies to the gRPC backend's health service, returning the service status.
- Created a shared parse handler in `parse.rs` for processing requests from both v1 and v2 parse endpoints, with appropriate error handling and response formatting.
- Introduced a new module `handlers` to organize the health and parse handlers.
- Established application state management in `state.rs` to hold gRPC clients.
- Added `turnkey.rs` for handling request/response envelopes specific to parse endpoints.
- Configured x402 settings in `x402_config.rs` to load from environment variables, including profile management and price tag configurations.
- Developed a mock facilitator service in `mock-facilitator` for testing purposes, including endpoints for verification and settlement.
- Included tests for the new functionality to ensure reliability and correctness.
@andrestielau andrestielau force-pushed the spec/x402-gated-http-api branch from 899cdbf to 35b6938 Compare May 15, 2026 01:01
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.

4 participants