feat: add REST API for programmatic resource registration#744
Open
Manishcs076 wants to merge 1 commit intoMerit-Systems:mainfrom
Open
feat: add REST API for programmatic resource registration#744Manishcs076 wants to merge 1 commit intoMerit-Systems:mainfrom
Manishcs076 wants to merge 1 commit intoMerit-Systems:mainfrom
Conversation
Exposes the existing tRPC register functionality as a public REST
endpoint at POST /api/resources/register.
Supports:
- Single resource: { "url": "https://..." }
- Batch registration: { "urls": ["https://...", ...] } (max 20)
- Probes each URL for x402 payment response before registering
- Returns discovery info for additional resources at the same origin
- Proper error responses (400 validation, 422 no 402/parse errors, 500 internal)
Fixes Merit-Systems#104
Contributor
|
@Manishcs076 is attempting to deploy a commit to the Merit Systems Team on Vercel. A member of the Team first needs to authorize it. |
| }, | ||
| }, | ||
| { status: 500 } | ||
| ); |
Contributor
Comment on lines
+209
to
+214
| return NextResponse.json({ | ||
| success: true, | ||
| registered: registered.length, | ||
| failed: failed.length, | ||
| results, | ||
| }); |
Contributor
There was a problem hiding this comment.
Suggested change
| return NextResponse.json({ | |
| success: true, | |
| registered: registered.length, | |
| failed: failed.length, | |
| results, | |
| }); | |
| // Determine success: at least one URL must be successfully registered | |
| const hasAnySuccess = registered.length > 0; | |
| const status = hasAnySuccess ? 200 : 422; | |
| return NextResponse.json( | |
| { | |
| success: hasAnySuccess, | |
| registered: registered.length, | |
| failed: failed.length, | |
| results, | |
| }, | |
| { status } | |
| ); |
Batch registration always returns success: true even when all URLs fail to register, with HTTP 200 status code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Exposes the existing internal tRPC register functionality as a public REST API endpoint.
Fixes #104
Endpoint
POST /api/resources/registerSingle resource:
{ "url": "https://example.com/api/resource" }Batch registration (up to 20):
{ "urls": ["https://example.com/api/a", "https://example.com/api/b"] }Behavior
registerResource()andprobeX402Endpoint()logicChanges
apps/scan/src/app/api/resources/register/route.ts(215 lines)