| outline |
|
||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| title | REQUEST_PARAM_TYPE Annotation | ||||||||||||||||||||||||||||
| titleTemplate | NpgsqlRest | ||||||||||||||||||||||||||||
| description | Control parameter transmission method for PostgreSQL REST API endpoints. Choose between query string and request body parameters. | ||||||||||||||||||||||||||||
| head |
|
::: info Also known as
param_type (with or without @ prefix)
The bare value keywords also work as standalone annotations: query_string / query (same as @request_param_type query_string) and body_json / body (same as @request_param_type body_json).
:::
Control how parameters are transmitted to the endpoint - via query string or request body.
@request_param_type <type>
@param_type <type>
type: query_string, query, body, body_json
| Value | Description |
|---|---|
query_string |
Parameters from URL query string |
query |
Same as query_string |
body_json |
Parameters from JSON request body |
body |
Same as body_json |
When not specified:
GETandDELETEmethods use query string- All other methods use JSON body
create function search_users(_name text, _active bool)
returns setof users
language sql
begin atomic;
select * from users where name ilike '%' || _name || '%' and active = _active;
end;
comment on function search_users(text, bool) is
'HTTP GET
@request_param_type query_string';Equivalent as a SQL file endpoint (sql/search-users.sql):
/*
HTTP GET
@request_param_type query_string
@param $1 name
@param $2 active boolean
*/
select * from users where name ilike '%' || $1 || '%' and active = $2;Request: GET /api/search-users?_name=john&_active=true
create function get_filtered_data(_filters text)
returns json
language sql
begin atomic;
...;
end;
comment on function get_filtered_data(text) is
'HTTP GET
@request_param_type body_json';Request:
GET /api/get-filtered-data
Content-Type: application/json
{"_filters": "status=active"}-- Using '@param_type' instead of '@request_param_type'
comment on function func1(text) is
'HTTP
@param_type query';
-- Using 'BODY' (case-insensitive)
comment on function func2(text) is
'HTTP
@param_type BODY';Override the default body behavior for POST:
create function quick_action(_id int)
returns text
language sql
begin atomic;
...;
end;
comment on function quick_action(int) is
'HTTP POST
@param_type query_string';Request: POST /api/quick-action?_id=123
When parameter type doesn't match the request format, the endpoint returns 404 Not Found:
- Endpoint configured for
query_stringbut receives JSON body → 404 - Endpoint configured for
body_jsonbut receives query parameters → 404
- NpgsqlRest Options configuration - Configure default parameter handling
- Comment Annotations Guide - How annotations work
- Configuration Guide - How configuration works
- HTTP - Define endpoint method
- BODY_PARAMETER_NAME - Specify body parameter
- QUERY_STRING_NULL_HANDLING - NULL handling