routes Command
The routes command displays all configured payment-protected endpoints.
npx x402test routes [options]What It Does
Section titled “What It Does”- Loads Configuration: Reads
x402test.config.js - Parses Routes: Extracts route information
- Displays Summary: Shows endpoints, prices, and descriptions
Options
Section titled “Options”—config, -c
Section titled “—config, -c”Specify a custom configuration file.
npx x402test routes --config ./custom.config.jsDefault: ./x402test.config.js
Output
Section titled “Output”Configured Routes:
/api/premium: Premium content access Price: 0.10 USDC Response: { "data": "This is premium content!", "timestamp": 1699564800000 } Status: 200
/api/data: Data API access Price: 0.01 USDC Response: [Function: response] Status: 200Examples
Section titled “Examples”Basic Usage
Section titled “Basic Usage”npx x402test routesCustom Config
Section titled “Custom Config”npx x402test routes --config ./production.config.jsSave to File
Section titled “Save to File”npx x402test routes > routes.txtFilter with grep
Section titled “Filter with grep”npx x402test routes | grep "Price:"Understanding Output
Section titled “Understanding Output”Route Path
Section titled “Route Path”/api/premium: Premium content access/api/premium: Endpoint URL pathPremium content access: Description from config
Price: 0.10 USDCAmount in USDC required to access this endpoint.
Response
Section titled “Response” Response: { "data": "This is premium content!", "timestamp": 1699564800000 }Shows the response structure:
- Static responses: Full JSON displayed
- Dynamic responses: Shows
[Function: response]
Status
Section titled “Status” Status: 200HTTP status code returned on successful payment.
Configuration Reference
Section titled “Configuration Reference”Routes are defined in x402test.config.js:
export default { routes: { "/api/premium": { price: "0.10", description: "Premium content access", status: 200, response: { data: "This is premium content!", }, }, "/api/data": { price: "0.01", description: "Data API access", status: 200, response: (req) => ({ method: req.method, path: req.path, data: { message: "Your data here" }, }), }, },};Error Handling
Section titled “Error Handling”Config Not Found
Section titled “Config Not Found”✘ Failed to load config: Config file not found: ./x402test.config.jsSolution:
npx x402test initnpx x402test routesInvalid Config
Section titled “Invalid Config”✘ Failed to load config: Invalid configuration formatSolutions:
- Check config file syntax
- Ensure proper ES6 module export
- Validate route structure
No Routes Configured
Section titled “No Routes Configured”Configured Routes:
(empty)Solution: Add routes to config file.
Use Cases
Section titled “Use Cases”Documentation
Section titled “Documentation”Generate route documentation:
npx x402test routes > API.mdValidation
Section titled “Validation”Verify routes before deployment:
npx x402test routesCheck output for:
- Correct prices
- Proper descriptions
- Valid response structures
Team Communication
Section titled “Team Communication”Share route configuration with team:
npx x402test routes | pbcopy # macOSnpx x402test routes | xclip # LinuxIntegration Testing
Section titled “Integration Testing”Use route info in tests:
#!/bin/bashroutes=$(npx x402test routes)echo "$routes"Comparing Configurations
Section titled “Comparing Configurations”Compare different configs:
npx x402test routes --config dev.config.js > dev-routes.txt
npx x402test routes --config prod.config.js > prod-routes.txt
diff dev-routes.txt prod-routes.txtScripting
Section titled “Scripting”Extract All Prices
Section titled “Extract All Prices”npx x402test routes | grep "Price:" | awk '{print $2, $3}'Count Routes
Section titled “Count Routes”npx x402test routes | grep -c "Price:"List Only Endpoints
Section titled “List Only Endpoints”npx x402test routes | grep "^/" | awk -F: '{print $1}'JSON Output (Future)
Section titled “JSON Output (Future)”Currently outputs human-readable format. For JSON output:
// In your scriptimport { loadConfig } from "x402test/server/config.js";
const config = await loadConfig("./x402test.config.js");console.log(JSON.stringify(config.routes, null, 2));Best Practices
Section titled “Best Practices”- Regular Checks: Run before deployment
- Documentation: Keep route list updated
- Validation: Verify prices and descriptions
- Automation: Include in CI/CD pipeline
- Version Control: Track route changes in git
Integration with Testing
Section titled “Integration with Testing”Use route info in tests:
import { loadConfig } from "x402test/server/config.js";import { x402 } from "x402test";
describe("All Routes", () => { let config;
beforeAll(async () => { config = await loadConfig("./x402test.config.js"); });
Object.entries(config.routes).forEach(([path, route]) => { it(`should access ${path}`, async () => { const response = await x402(`http://localhost:4402${path}`) .withPayment(route.price) .expectStatus(route.status || 200) .execute();
expect(response.payment).toBeDefined(); }); });});Next Steps
Section titled “Next Steps”- init Command - Initialize configuration
- start Command - Start mock server
- Mock Server - Configure routes