Reflect 4 Proxy May 2026
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method;public class LoggingHandler implements InvocationHandler private final Object target; // real object
public LoggingHandler(Object target) this.target = target; @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable // Log before execution System.out.println("[LOG] Calling: " + method.getName()); if (args != null) for (int i = 0; i < args.length; i++) System.out.println("[LOG] Arg " + i + ": " + args[i]); // Invoke the real method via reflection Object result = method.invoke(target, args); // Log after execution System.out.println("[LOG] Returned: " + result); return result;
If the user is specifically looking for the NPM package reflect-proxy, version 4 introduced middleware support for altering the reflection. reflect 4 proxy
npm install -g reflect-proxy@4
Configuration file (reflect.config.json):
"version": 4,
"port": 8080,
"mode": "echo",
"reflection":
"addHeaders": true,
"stripAuth": false,
"maxBodySize": "10mb"
Run the server:
reflect-proxy --config reflect.config.json
Testing it:
curl -X POST http://localhost:8080/api/test \
-H "Content-Type: application/json" \
-H "X-Debug-Token: mySecret" \
-d '"hello":"world"'
Expected Output (Reflected):
"originalMethod": "POST",
"originalPath": "/api/test",
"originalHeaders":
"content-type": "application/json",
"x-debug-token": "mySecret",
"host": "localhost:8080"
,
"originalBody":
"hello": "world"
,
"timestamp": "2025-01-27T12:00:00Z"
const user = name: "Alice", age: 25 ;const handler = get(target, prop, receiver) console.log(
GET $prop); return Reflect.get(target, prop, receiver); , set(target, prop, value, receiver) , has(target, prop) console.log(HAS $prop); return Reflect.has(target, prop); , deleteProperty(target, prop) console.log(DELETE $prop); return Reflect.deleteProperty(target, prop); ;const pUser = new Proxy(user, handler);
pUser.age = 30; // SET age=30 console.log(pUser.name); // GET name → Alice console.log('age' in pUser); // HAS age → true delete pUser.name; // DELETE name