Skip to main content

fetchSync() Function

The fetchSync() function allows you to make http(s) requests to backend servers to record or query information. The syntax is similar to the standard fetch API, however with the difference that fetchSync does not return a promise and instead executes the request synchronously.


This policy will print the current IP address of the node where jsPolicy runs on and tries to query an address that does not exist.

kind: JsPolicy
name: ""
operations: ["CREATE"]
resources: ["pods"]
javascript: |
// use fetchSync to make requests to backend servers
const res = fetchSync("", {
method: "GET",
headers: {
"X-Custom-HTTP-Header": "test"
if (res.ok) {
print("jspolicy ip: " + res.json().ip);
// you can also use try catch to handle network errors
try {
} catch(err) {
print("Catched fetchSync: " + err);