Skip to content

Express to HTTP migration

The deprecated Express type of Val is being replaced by HTTP on October 1, 2024. If you still have Express vals running and want to upgrade them, here are some tips for doing so. Reach out to us if you need help with the process.

Parameters

  • Express vals took two arguments: a request and a response, and their return value was ignored.
  • HTTP vals receive a Request as an argument and they need to return a Response object to reply.

Here are equivalent vals for the express versus HTTP types:

// Express handler
export function handler(req, res) {
res.send("Hello world");
}
// HTTP handler
export function handler(req) {
return new Response("Hello world");
}

The response object

Where with express vals, you set the response status, headers, and other details by chaining functions off of the response object, with the HTTP type, these are options you set for the Response object.

// Express handler
export function handler(req, res) {
res.status(200).set("Content-Type", "text/plain").send("Hello world");
}
// HTTP handler
export function handler(req) {
return new Response("Hello world", {
status: 200,
headers: {
"Content-Type": "text/plain",
},
});
}

The request object

The request object for the express handler looks like an express Request object, which is based on a Node.js request object. The Request object for the HTTP handler is the web-standard Request object. This means that some things, like getting query string parameters, will require different code:

// Express handler
export function handler(req, res) {
res.send(req.query.name);
}
// HTTP handler
export function handler(req) {
return new Response(new URL(req.url).searchParams.get("name"));
}

Endpoints

HTTP vals can be accessed by subdomains ending in web.val.run, like https://username-valname.web.val.run. Express vals are accessed on a different subdomain path, ending in express.val.run. You may need to update code and links that point to the val.