Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

better-call

Latest version: v1.4.6

Overview

Last scanned
18 Nov 2026
Published
18 Nov 2026
npm package Publisher: bekacru
823 Stars
61 Forks
99 Versions
75.6M Downloads
TypeScript Repo language

Scan summary

better-call was last scanned on 18 Nov 2026 at version 1.4.6. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 99 versions; the latest was published on 18 Nov 2026.
  • Findings: No rules fired in version 1.4.6.
  • Downloads: 75,606,416 downloads.

Versions

99 versions published
Versions and the rules that fired in each
VersionPublishedStatus
1.4.6 LATEST 18 Nov 2026 No rules fired
0.0.0-experimental.21243e78 9 Nov 2026 No rules fired
0.0.0-experimental.f8a3a2ca 9 Nov 2026 No rules fired
1.4.5 3 Nov 2026 Not shown
0.0.0-experimental.fffed085 31 Oct 2026 Not shown

No rules fired in 1.4.6

Findings

Findings for v1.4.6. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 1.4.6; other versions have their own rules, not their own score.

Known vulnerabilities

1 CVE · last 11 Jul 2025

0 CRITICAL 0 HIGH 1 MEDIUM 0 LOW

Versions

  • ≥ 1.0.12
  • < 1.0.12 1 MEDIUM

Vulnerabilities

  • GHSA-HQ75-XG7R-RX6C Medium 11 Jul 2025 Better Call routing bug can lead to Cache Deception Fixed in 1.0.12

README

The publisher’s own README, as collected from the registry.

Better Call

Better call is a tiny web framework for creating endpoints that can be invoked as a normal function or mounted to a router to be served by any web standard compatible server (like Bun, node, nextjs, sveltekit...) and also includes a typed RPC client for type-safe client-side invocation of these endpoints.

Built for typescript and it comes with a very high performance router based on rou3.

Install

pnpm i better-call

Make sure to install standard schema compatible validation library like zod.

pnpm i zod

Usage

The building blocks for better-call are endpoints. You can create an endpoint by calling createEndpoint and passing it a path, options and a handler that will be invoked when the endpoint is called.

// endpoint.ts
import { createEndpoint } from "better-call"
import { z } from "zod"

export const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    return {
        item: {
            id: ctx.body.id
        }
    }
})

// Now you can call the endpoint just as a normal function.
const item = await createItem({
    body: {
        id: "123"
    }
})

console.log(item); // { item: { id: '123' } }

OR you can mount the endpoint to a router and serve it with any web standard compatible server.

The example below uses Bun

// router.ts
import { createRouter } from "better-call"
import { createItem } from "./endpoint"

export const router = createRouter({
    createItem
})

Bun.serve({
    fetch: router.handler
})

Then you can use the rpc client to call the endpoints on client.

// client.ts
import type { router } from "./router" // import router type
import { createClient } from "better-call/client"

const client = createClient<typeof router>({
    baseURL: "http://localhost:3000"
})

const item = await client("@post/item", {
    body: {
        id: "123"
    }
})

console.log(item) // { data: { item: { id: '123' } }, error: null }
Endpoint

Endpoints are building blocks of better-call.

Path

The path is the URL path that the endpoint will respond to. It can be a direct path or a path with parameters and wildcards.

// direct path
const endpoint = createEndpoint("/item", {
    method: "GET",
}, async (ctx) => {})

// path with parameters
const endpoint = createEndpoint("/item/:id", {
    method: "GET",
}, async (ctx) => {
    return {
        item: {
            id: ctx.params.id
        }
    }
})

// path with wildcards
const endpoint = createEndpoint("/item/**:name", {
    method: "GET",  
}, async (ctx) => {
    // the name will be the remaining path
    ctx.params.name
})
Body Schema

The body option accepts a standard schema and will validate the request body. If the request body doesn't match the schema, the endpoint will throw a validation error. If it's mounted to a router, it'll return a 400 error with the error details.

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    return {
        item: {
            id: ctx.body.id
        }
    }
})
Query Schema

The query option accepts a standard schema and will validate the request query. If the request query doesn't match the schema, the endpoint will throw a validation error. If it's mounted to a router, it'll return a 400 error with the error details.

const createItem = createEndpoint("/item", {
    method: "GET",
    query: z.object({
        id: z.string()
    })
}, async (ctx) => {
    return {
        item: {
            id: ctx.query.id
        }
    }
})
Method

You can specify a single HTTP method or an array of methods for an endpoint.

// Single method
const getItem = createEndpoint("/item", {
    method: "GET",
}, async (ctx) => {
    return { item: "data" }
})

// Multiple methods
const itemEndpoint = createEndpoint("/item", {
    method: ["GET", "POST"],
}, async (ctx) => {
    if (ctx.method === "POST") {
        // handle POST - create/update
        return { created: true }
    }
    // handle GET - read only
    return { item: "data" }
})

When calling an endpoint with multiple methods directly (not through HTTP), the method parameter is optional and defaults to the first method in the array:

// Defaults to "GET" (first in array)
const result = await itemEndpoint({ headers })

// Explicitly specify POST
const result = await itemEndpoint({ headers, method: "POST" })
Media types

By default, all media types are accepted, but only a handful of them have a built-in support:

  • application/json and custom json suffixes are parsed as a JSON (plain) object
  • application/x-www-form-urlencoded and multipart/form-data are parsed as a FormData object
  • text/plain is parsed as a plain string
  • application/octet-stream is parsed as an ArrayBuffer
  • application/pdf, image/* and video/* are parsed as Blob
  • application/stream is parsed as ReadableStream
  • Any other media type that is not recognized, will be parsed as a plain string.

Similarly, returning a supported type from a handler will properly serialize it with the correct Content-Type as specified above.

Allowed Media Types

You can restrict which media types (MIME types) are allowed for request bodies using the allowedMediaTypes option. This can be configured at both the router level and the endpoint level, with endpoint-level configuration taking precedence.

When a request is made with a disallowed media type, the endpoint will return a 415 Unsupported Media Type error.

Note: Please note that using this option won't add parsing support for new media types, it only restricts the media types that are already supported.

Router-level configuration:

const router = createRouter({
    createItem,
    updateItem
}, {
    // All endpoints in this router will only accept JSON
    allowedMediaTypes: ["application/json"]
})

Endpoint-level configuration:

const uploadFile = createEndpoint("/upload", {
    method: "POST",
    metadata: {
        // This endpoint will only accept form data
        allowedMediaTypes: ["multipart/form-data"]
    }
}, async (ctx) => {
    return { success: true }
})

Multiple media types:

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    }),
    metadata: {
        // Accept both JSON and form-urlencoded
        allowedMediaTypes: [
            "application/json",
            "application/x-www-form-urlencoded"
        ]
    }
}, async (ctx) => {
    return {
        item: {
            id: ctx.body.id
        }
    }
})

Endpoint overriding router:

const router = createRouter({
    createItem,
    uploadFile
}, {
    // Default: only accept JSON
    allowedMediaTypes: ["application/json"]
})

const uploadFile = createEndpoint("/upload", {
    method: "POST",
    metadata: {
        // This endpoint overrides the router setting
        allowedMediaTypes: ["multipart/form-data", "application/octet-stream"]
    }
}, async (ctx) => {
    return { success: true }
})

Note: The validation is case-insensitive and handles charset parameters automatically (e.g., application/json; charset=utf-8 will match application/json).

Require Headers

The requireHeaders option is used to require the request to have headers. If the request doesn't have headers, the endpoint will throw an error. This is only useful when you call the endpoint as a function.

const createItem = createEndpoint("/item", {
    method: "GET",
    requireHeaders: true
}, async (ctx) => {
    return {
        item: {
            id: ctx.headers.get("id")
        }
    }
})
createItem({
    headers: new Headers()
})
Require Request

The requireRequest option is used to require the request to have a request object. If the request doesn't have a request object, the endpoint will throw an error. This is only useful when you call the endpoint as a function.

const createItem = createEndpoint("/item", {
    method: "GET",
    requireRequest: true
}, async (ctx) => {
    return {
        item: {
            id: ctx.request.id
        }
    }
})

createItem({
    request: new Request()
})
Handler

This is the function that will be invoked when the endpoint is called. The signature is:

const handler = async (ctx) => response;

Where ctx is:

  • The context object containing the request, headers, body, query, params and a few helper functions. If there is a middleware, the context will be extended with the middleware context.

And response is any supported response type:

  • a Response object
  • any javascript value: string, number, boolean, an object or an array
  • the return value of the ctx.json() helper

Below, we document all the ways in which you can create a response in your handler:

Returning a response

You can use the ctx.setStatus(status) helper to change the default status code of a successful response:

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    ctx.setStatus(201);
    return {
        item: {
            id: ctx.body.id
        }
    }
})

Sometimes, you want to respond with an error, in those cases you will need to throw better-call's APIError error or use the ctx.error() helper, they both have the same signatures! If the endpoint is called as a function, the error will be thrown but if it's mounted to a router, the error will be converted to a response object with the correct status code and headers.

import { APIError } from "better-call"

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    if (ctx.body.id === "123") {
        throw ctx.error("BAD_REQUEST", {
            message: "Id is not allowed"
        })
    }

    if (ctx.body.id === "456") {
        throw new APIError("BAD_REQUEST", {
            message: "Id is not allowed"
        })
    }
    return {
        item: {
            id: ctx.body.id
        }
    }
})

You can also instead throw using a status code:

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    if (ctx.body.id === "123") {
        throw ctx.error(400, {
            message: "Id is not allowed"
        })
    }
    return {
        item: {
            id: ctx.body.id
        }
    }
})

You can also specify custom response headers:

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    if (ctx.body.id === "123") {
        throw ctx.error(
            400,
            { message: "Id is not allowed" },
            { "x-key": "value" } // custom response headers
        );
    }
    return {
        item: {
            id: ctx.body.id
        }
    }
})

Or create a redirection:

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    if (ctx.body.id === "123") {
        throw ctx.redirect("/item/123");
    }
    return {
        item: {
            id: ctx.body.id
        }
    }
})

Or use the ctx.json() to return any object:

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    return ctx.json({
        item: {
            id: ctx.body.id
        }
    })
})

Finally, you can return a new Response object. In this case, the ctx.setStatus() call will be ignored, as the Response will have completely control over the final status code:

const createItem = createEndpoint("/item", {
    method: "POST",
    body: z.object({
        id: z.string()
    })
}, async (ctx) => {
    return Response.json({
        item: {
            id: ctx.body.id
        }
    }, { status: 201 });
})

Note: Please note that when using the Response API, your endpoint will not return the JSON object even if you use the Response.json() helper, you'll always get a Response as a result.

Middleware

Endpoints can use middleware by passing the use option to the endpoint. To create a middleware, you can call createMiddleware and pass it a function or an options object and a handler function.

If you return a context object from the middleware, it will be available in the endpoint context.

import { createMiddleware, createEndpoint } from "better-call";

const middleware = createMiddleware(async (ctx) => {
    return {
        name: "hello"
    }
})

const endpoint = createEndpoint("/", {
    method: "GET",
    use: [middleware],
}, async (ctx) => {
   // this will be the context object returned by the middleware with the name property
   ctx.context
})
Router

You can create a router by calling createRouter and passing it an array of endpoints. It returns a router object that has a handler method that can be used to serve the endpoints.

import { createRouter } from "better-call"
import { createItem } from "./item"

const router = createRouter({
    createItem
})

Bun.serve({
    fetch: router.handler
})

Behind the scenes, the router uses rou3 to match the endpoints and invoke the correct endpoint. You can look at the rou3 documentation for more information.

Virtual endpoints

You can create virtual endpoints by completely omitting the path. Virtual endpoints do not get exposed for routing, do not generate OpenAPI docs and cannot be inferred through the RPC client, but they can still be invoked directly:

import { createEndpoint, createRouter } from "better-call";

const endpoint = createEndpoint({
    method: "GET",
}, async (ctx) => {
   return "ok";
})

const response = await endpoint(); // this works

const router = createRouter({ endpoint })

Bun.serve({
    fetch: router.handler // endpoint won't be routed through the router handler
});
Scoped endpoints

You can also create endpoints that are exposed for routing, but that cannot be inferred through the client by using the metadata.scope option:

  • rpc - the endpoint is exposed to the router, can be invoked directly and is available to the RPC client
  • server - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
  • http - the endpoint is only exposed to the router
import { createEndpoint, createRouter } from "better-call";

const endpoint = createEndpoint("/item", {
    method: "GET",
    metadata: {
        scope: "server"
    },
}, async (ctx) => {
   return "ok";
})

const response = await endpoint(); // this works

const router = createRouter({
    endpoint
})

Bun.serve({
    fetch: router.handler // endpoint won't be routed through the router handler
})
Router Options

routerMiddleware:

A router middleware is similar to an endpoint middleware but it's applied to any path that matches the route. It's like any traditional middleware. You have to pass endpoints to the router middleware as an array.

const routeMiddleware = createEndpoint("/api/**", {
    method: "GET",
}, async (ctx) => {
    return {
        name: "hello"
    }
})
const router = createRouter({
    createItem
}, {
    routerMiddleware: [{
        path: "/api/**",
        middleware:routeMiddleware
    }]
})

basePath: The base path for the router. All paths will be relative to this path.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm better-call

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

Ethersphere Hijacked With Crypto Stealing Malware (1)
npm

Ethersphere Hijacked With Crypto Stealing Malware Via Github & npm

Copy of Template Design OX Blog (2)
Research

NGINX2Root: Five Critical NGINX Flaws Expose Web Servers to Remote Code Execution

Frame 2085668439 (1)
Group 1261154229