From 46a0fc1dc83ba03d2b581bb2bd6fddd06a223ece Mon Sep 17 00:00:00 2001 From: Viswa Marepalli Date: Thu, 12 Nov 2026 12:41:42 +0000 Subject: [PATCH] docs: update examples to use Response.json --- docs/docs/agents/getting-started.md | 2 +- docs/docs/agents/routing.md | 2 +- docs/docs/agents/state.md | 2 +- docs/docs/agents/sub-agents.md | 2 +- docs/docs/agents/tasks.md | 2 +- docs/docs/containers/examples.md | 2 +- docs/docs/containers/outbound-traffic.md | 2 +- docs/docs/containers/routing.md | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/docs/agents/getting-started.md b/docs/docs/agents/getting-started.md index 0f79a9e..d83b06a 100644 --- a/docs/docs/agents/getting-started.md +++ b/docs/docs/agents/getting-started.md @@ -44,7 +44,7 @@ class Counter(Agent): async def on_request(self, request: Request) -> Response: if request.method == "POST": await self.increment() - return Response.from_json(self.state) + return Response.json(self.state) class Default(WorkerEntrypoint): diff --git a/docs/docs/agents/routing.md b/docs/docs/agents/routing.md index cc88989..7350343 100644 --- a/docs/docs/agents/routing.md +++ b/docs/docs/agents/routing.md @@ -185,7 +185,7 @@ class Default(WorkerEntrypoint): async def fetch(self, request: Request) -> Response: counter = await get_agent_by_name(self.env.Counter, "from-worker") count = await counter.increment(5) - return Response.from_json({"count": count}) + return Response.json({"count": count}) ``` ```json diff --git a/docs/docs/agents/state.md b/docs/docs/agents/state.md index 868388d..c532533 100644 --- a/docs/docs/agents/state.md +++ b/docs/docs/agents/state.md @@ -121,7 +121,7 @@ class Notes(Agent): if request.method == "POST": self.sql("INSERT INTO notes (text) VALUES (?)", await request.text()) rows = self.sql("SELECT id, text FROM notes ORDER BY id") - return Response.from_json(list(rows)) + return Response.json(list(rows)) ``` ```sh diff --git a/docs/docs/agents/sub-agents.md b/docs/docs/agents/sub-agents.md index 4f9e95d..54074b8 100644 --- a/docs/docs/agents/sub-agents.md +++ b/docs/docs/agents/sub-agents.md @@ -37,7 +37,7 @@ class Inbox(Agent): thread = await self.dynamic_agents.get(Thread, "t1") count = await thread.add("hi") names = [child.name for child in self.dynamic_agents.list()] - return Response.from_json({"count": count, "threads": names}) + return Response.json({"count": count, "threads": names}) ``` ```json diff --git a/docs/docs/agents/tasks.md b/docs/docs/agents/tasks.md index b69cfa5..4896721 100644 --- a/docs/docs/agents/tasks.md +++ b/docs/docs/agents/tasks.md @@ -47,7 +47,7 @@ from workers import Request, Response class Reports(Agent): async def on_request(self, request: Request) -> Response: receipt = await self.build.run({"rows": 21}) - return Response.from_json({"run_id": receipt.run_id, "state": receipt.state}) + return Response.json({"run_id": receipt.run_id, "state": receipt.state}) ``` ```json diff --git a/docs/docs/containers/examples.md b/docs/docs/containers/examples.md index 6fc6e96..9983a35 100644 --- a/docs/docs/containers/examples.md +++ b/docs/docs/containers/examples.md @@ -291,7 +291,7 @@ from workers import Request, Response async def fake_weather( request: Request, env: Any, ctx: OutboundHandlerContext ) -> Response: - return Response.from_json({"city": "Lisbon", "temp_c": 21}) + return Response.json({"city": "Lisbon", "temp_c": 21}) class Sandbox(Container): diff --git a/docs/docs/containers/outbound-traffic.md b/docs/docs/containers/outbound-traffic.md index adaf10a..269e5ae 100644 --- a/docs/docs/containers/outbound-traffic.md +++ b/docs/docs/containers/outbound-traffic.md @@ -107,7 +107,7 @@ hostname match takes precedence over a glob: async def mock_payments( request: Request, env: Any, ctx: OutboundHandlerContext ) -> Response: - return Response.from_json({"status": "succeeded"}) + return Response.json({"status": "succeeded"}) async def block(request: Request, env: Any, ctx: OutboundHandlerContext) -> Response: diff --git a/docs/docs/containers/routing.md b/docs/docs/containers/routing.md index c138993..37302e2 100644 --- a/docs/docs/containers/routing.md +++ b/docs/docs/containers/routing.md @@ -182,7 +182,7 @@ class Default(WorkerEntrypoint): result: TranscodeResult = await container.transcode( "https://example.com/in.mp4", "720p" ) - return Response.from_json(result) + return Response.json(result) ``` ## Check requests before they reach the container