Skip to main content

routes

Creates, updates, deletes, gets or lists a routes resource.

Overview

Nameroutes
TypeResource
Idvercel.project_routes.routes

Fields

The following fields are returned by SELECT queries:

A routing rule with metadata for project-level routing.

NameDatatypeDescription
idstringUnique identifier for the routing rule.
namestringHuman-readable name for the routing rule.
descriptionstringOptional description of what the routing rule does.
enabledbooleanWhether the routing rule is enabled. Defaults to true. (false, true)
raw_deststringOriginal destination provided by user. (wire: rawDest)
raw_srcstringOriginal source pattern provided by user (path-to-regexp or regex). Used to display the user's input in API responses. (wire: rawSrc)
routeobjectThe route definition from @vercel/routing-utils.
route_typestringComputed route type based on the route configuration. Only present in API responses, not stored in S3. (redirect, rewrite, set_status, transform) (wire: routeType)
src_syntaxstringThe syntax type of the source pattern. Determines how the pattern is compiled to regex. (equals, path-to-regexp, regex) (wire: srcSyntax)
stagedbooleanWhether this route is new and not yet published to production. Set to true only when a route is first created via add-route. Cleared (set to false) when a version is promoted to production. (false, true)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
listselectproject_idversion_id, q, filter, diff, team_id, slugGet the routing rules for a project. Supports searching by name/ID/pattern, filtering by route type, and diffing staged changes against production.
createinsertproject_id, routeteam_id, slugAdd a single routing rule to a project at a specified position. Defaults to the end of the list if no position is provided. The route is enabled by default. Stages a new version with the added route.
updateupdateproject_id, route_idteam_id, slugReplace a routing rule identified by its ID, or restore it from the current production version. Stages a new version with the modified route.
stagereplaceproject_idteam_id, slugStage routing rules for a project. Set overwrite to true to replace all existing rules, or omit it to merge with existing rules by ID. Returns the new staged version.
deletedeleteproject_idteam_id, slugDelete one or more routing rules from a project by ID. Stages a new version with the routes removed.
generateexecproject_id, promptteamId, slugGenerate a routing rule configuration from a natural language description. Returns a suggested route configuration that can be reviewed and saved.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
project_idstring
route_idstring
diff
filterstring
qstring
slugstringThe Team slug to perform the request on behalf of.
teamIdstringThe Team identifier to perform the request on behalf of.
team_idstringThe Team identifier to perform the request on behalf of. (wire: teamId)
version_idstring (wire: versionId)

SELECT examples

Get the routing rules for a project. Supports searching by name/ID/pattern, filtering by route type, and diffing staged changes against production.

SELECT
id,
name,
description,
enabled,
raw_dest,
raw_src,
route,
route_type,
src_syntax,
staged
FROM vercel.project_routes.routes
WHERE project_id = '{{ project_id }}' -- required
AND version_id = '{{ version_id }}'
AND q = '{{ q }}'
AND filter = '{{ filter }}'
AND diff = '{{ diff }}'
AND team_id = '{{ team_id }}'
AND slug = '{{ slug }}'
;

INSERT examples

Add a single routing rule to a project at a specified position. Defaults to the end of the list if no position is provided. The route is enabled by default. Stages a new version with the added route.

INSERT INTO vercel.project_routes.routes (
route,
position,
project_id,
team_id,
slug
)
SELECT
'{{ route }}' /* required */,
'{{ position }}',
'{{ project_id }}',
'{{ team_id }}',
'{{ slug }}'
RETURNING
route,
version
;

UPDATE examples

Replace a routing rule identified by its ID, or restore it from the current production version. Stages a new version with the modified route.

UPDATE vercel.project_routes.routes
SET
route = '{{ route }}',
restore = {{ restore }}
WHERE
project_id = '{{ project_id }}' --required
AND route_id = '{{ route_id }}' --required
AND team_id = '{{ team_id}}'
AND slug = '{{ slug}}'
RETURNING
route,
version;

REPLACE examples

Stage routing rules for a project. Set overwrite to true to replace all existing rules, or omit it to merge with existing rules by ID. Returns the new staged version.

REPLACE vercel.project_routes.routes
SET
overwrite = {{ overwrite }},
routes = '{{ routes }}'
WHERE
project_id = '{{ project_id }}' --required
AND team_id = '{{ team_id}}'
AND slug = '{{ slug}}'
RETURNING
version;

DELETE examples

Delete one or more routing rules from a project by ID. Stages a new version with the routes removed.

DELETE FROM vercel.project_routes.routes
WHERE project_id = '{{ project_id }}' --required
AND team_id = '{{ team_id }}'
AND slug = '{{ slug }}'
;

Lifecycle Methods

EXEC variables use wire (API) names.

Generate a routing rule configuration from a natural language description. Returns a suggested route configuration that can be reviewed and saved.

EXEC vercel.project_routes.routes.generate
@project_id='{{ project_id }}' --required,
@teamId='{{ teamId }}',
@slug='{{ slug }}'
@@json=
'{
"prompt": "{{ prompt }}",
"currentRoute": "{{ currentRoute }}"
}'
;