PATH
Set a custom endpoint path. Alternative to specifying the path in the HTTP annotation.
Keywords
@path, path
Syntax
@path <url-path>Examples
Custom Path
create function get_user_data()
returns json
language sql
as $$...$$;
comment on function get_user_data() is
'HTTP GET
@path /users/data';Creates: GET /users/data
Path with HTTP Method
comment on function my_function() is
'HTTP GET
@path /custom/endpoint';Creates: GET /custom/endpoint
Versioned API
comment on function get_users_v2() is
'HTTP GET
@path /api/v2/users';Path Parameters
Paths can include parameter placeholders using the {param} syntax. Parameter values are extracted directly from the URL path.
Basic Path Parameter
create function get_user(user_id int)
returns json
language sql
as $$...$$;
comment on function get_user(int) is
'HTTP GET
@path /users/{user_id}';Call: GET /users/42 → user_id = 42
Nested Path Parameters
create function get_user_order(user_id int, order_id int)
returns json
language sql
as $$...$$;
comment on function get_user_order(int, int) is
'HTTP GET
@path /users/{user_id}/orders/{order_id}';Call: GET /users/42/orders/123 → user_id = 42, order_id = 123
Parameter Name Matching
Parameter names in {param} can use either:
- PostgreSQL snake_case name:
{user_id} - Converted camelCase name:
{userId}
Matching is case-insensitive.
Behavior
- Overrides the auto-generated path
- Path should start with
/for absolute paths - Can be used alongside HTTP annotation
- Path parameters can be combined with query string or body parameters
Related
- NpgsqlRest Options configuration - Configure URL prefixes, naming conventions
- Comment Annotations Guide - How annotations work
- Configuration Guide - How configuration works
Related Annotations
- HTTP - Define endpoint (can also set path)