The Simplest Way to Make Cloudflare Workers and Json Rpc Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Running cloudflare workers and json rpc lets teams process remote method calls at the network edge. The edge worker receives a JSON payload, checks the method name, and routes the call. This pairing cuts down on round trips between client apps and backend servers. Teams use it to handle fast API tasks, route blockchain requests, and join microservices. The edge script parses the request body and matches the method to a handler. It then runs the task and sends back a structured response. How c

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Running cloudflare workers and json rpc lets teams process remote method calls at the network edge. The edge worker receives a JSON payload, checks the method name, and routes the call.

This pairing cuts down on round trips between client apps and backend servers. Teams use it to handle fast API tasks, route blockchain requests, and join microservices. The edge script parses the request body and matches the method to a handler. It then runs the task and sends back a structured response.

How cloudflare workers and json rpc handle requests and keys

In a standard setup, the client sends a post request to the worker URL. That message holds the version string, the method name, the parameters, and a request ID. Since every call goes to one endpoint, standard URL path rules do not apply here. The worker must open the payload first to see what the caller wants to do.

Checking identity happens before the worker runs any business logic. The caller sends an API key or a signed token in the request headers. The worker reads this header and checks the key against an edge key store. Next, the script checks if that specific user role can run the requested method. Read methods might be open to many users, while write methods need strict role checks.

Once the check passes, the worker runs the task or calls a backend service. It formats the output with the matching request ID and returns it to the client. If a check fails, the worker sends back a standard error object right away.

Common failure modes and how to scope roles

Many teams make the mistake of using one shared service key for all backend calls. When an edge script uses a single broad token, every caller gets the same power. If a bad actor finds a bug in one method, they can reach everything. Shared keys also make it hard to see which user triggered a specific backend action.

JSON Web Tokens (JWT) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Another common issue is missing logs at the method level. Standard web logs only show a post request to the root path. They do not show the method name or the parameters inside the JSON body. Without body inspection, teams cannot tell a harmless status check from a risky data change. Sensitive fields like emails or phone numbers can also slip into plain text logs.

Batch requests bring another risk to edge scripts. A caller can pack hundreds of method calls into one JSON array. This single HTTP request can drain worker memory or overload a backend database. Teams should set strict limits on batch sizes at the start of the script.

To fix these issues, scope permissions down to individual method names. Map each caller identity to an explicit list of allowed methods. Use separate backend roles for read tasks and write tasks. Log the method name, the caller identity, and the request ID for every single call. Apply data masking to rewrite emails, card numbers, and national IDs in results and logs. Keep network paths tight by using mutual TLS between the edge and your origin servers.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Why do standard web firewalls miss bad JSON RPC calls?

Every call uses the same HTTP post method and the same URL path. A standard rule only sees normal traffic unless it parses the JSON body to check the method name.

How should teams handle batch requests at the edge?

Count the items in the JSON array before running any method logic. Reject the whole request right away if the array count goes over your safe limit.

Where should edge scripts store secret keys for backend services?

Store secret keys in encrypted edge bindings rather than plain text files. Rotate these keys often and give each worker script its own narrow role.

The query runs. The emails stay hidden.