Skip to content

Conversation

@akapug
Copy link
Member

@akapug akapug commented Dec 2, 2025

Ready for review Powered by Pull Request Badge

Summary

Implements the missing body-reading methods on FetchRequest interface:

  • text(): Returns body as string (UTF-8)
  • json(): Parses body as JSON
  • arrayBuffer(): Returns body as byte array

Changes

FetchRequest.kt (Interface)

  • Added interface method declarations for text(), json(), arrayBuffer()

FetchRequestIntrinsic.kt (Implementation)

  • Added rawBodyBytes constructor parameter for storing request body
  • Implemented readBodyBytes() helper method
  • Added text(), json(), arrayBuffer() implementations
  • Added ProxyExecutable wrappers in getMember() for GraalVM interop
  • Modified forRequest() factories to capture raw bytes

JsServerRequestExecutionInputs.kt (Server integration)

  • Added cachedBodyBytes field with lazy body reading
  • Implemented text(), json(), arrayBuffer() methods

Notes

  • Implementation is synchronous (returns values directly, not Promises)
  • A full async Promise implementation would need additional GraalVM integration
  • This unblocks basic MCP server and REST API use cases that need POST body parsing

Testing

Build verified: ./gradlew :packages:graalvm:compileKotlin passes

Fixes #1805

Implements the missing body-reading methods on FetchRequest:
- text(): Returns body as string (UTF-8)
- json(): Parses body as JSON
- arrayBuffer(): Returns body as byte array

This unblocks MCP server and REST API use cases that need
to read POST request bodies.

Fixes #1805
@akapug akapug requested a review from sgammon as a code owner December 2, 2025 11:45
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.

HTTP Server: Request.text() and Request.json() not implemented in beta11-rc3

2 participants