ALTER API statement
The ALTER API statement can be used to modify an existing defined API.
Statement syntax
SurrealQL Syntax
ALTER API [ IF EXISTS ] @endpoint
[ FOR any [ @api_config ] [ THEN @expression | DROP THEN ] ]
[ FOR @http_method, ... [ MIDDLEWARE @function, ... ] [ THEN @expression ] ]
[ FOR @http_method, ... DROP THEN ]
[ COMMENT @string | DROP COMMENT ]
Example usage
-- Define a simple API
DEFINE API "/test"
FOR get
THEN {
{
body: {
some: "data"
}
};
};
-- Make a random function
DEFINE FUNCTION fn::feeling_lucky() -> int {
rand::enum(200, 404)
};
-- Set it as the HTTP status
ALTER API "/test" FOR get THEN {
{
status: fn::feeling_lucky(),
body: {
some: "data"
}
}
};
-- status is either 200 or 404
api::invoke("/test");
Possible output
{
body: {
some: 'data'
},
headers: {
"x-surreal-request-id": '95fd0577-5b97-4dc1-b98e-c284f0e36a63'
},
request_id: '95fd0577-5b97-4dc1-b98e-c284f0e36a63',
status: 404
}