Skip to content

Latest commit

 

History

History
99 lines (77 loc) · 2.33 KB

File metadata and controls

99 lines (77 loc) · 2.33 KB
outline
2
3
title ALLOW_ANONYMOUS Annotation
titleTemplate NpgsqlRest
description Allow unauthenticated access to specific PostgreSQL REST API endpoints. Override global authorization requirements.
head
meta
name content
keywords
npgsqlrest allow anonymous, public endpoint, unauthenticated access, anonymous api, public api endpoint
meta
property content
og:title
NpgsqlRest ALLOW_ANONYMOUS Annotation
meta
property content
og:description
Allow unauthenticated access to specific endpoints, overriding global authorization.
meta
property content
og:type
article

ALLOW_ANONYMOUS

::: info Also known as anonymous, allow_anon, anon (with or without @ prefix) :::

Allow unauthenticated access to the endpoint, overriding the global RequiresAuthorization setting.

Syntax

@allow_anonymous

Examples

Public Endpoint

create function get_public_info()
returns json
language sql
begin atomic;
select '{"version": "1.0"}'::json;
end;

comment on function get_public_info() is
'HTTP GET
@allow_anonymous';

Equivalent as a SQL file endpoint (sql/get-public-info.sql):

-- HTTP GET
-- @allow_anonymous
select '{"version": "1.0"}'::json;

Short Form

comment on function health_check() is
'HTTP GET
@anon';

Public Read, Protected Write Pattern

-- Anyone can read
comment on function get_products() is
'HTTP GET
@allow_anonymous';

-- Only authenticated users can create
comment on function create_product(text, numeric) is
'HTTP POST
@authorize';

Behavior

  • Overrides the global RequiresAuthorization: true setting
  • Allows requests without authentication tokens
  • Useful for public APIs, health checks, and login endpoints

Related

Related Annotations