Versions in this module Expand all Collapse all v0 v0.11.0 Jul 6, 2026 Changes in this version + const DefaultBodyLimit + const NonFieldErrors + var ErrAuthenticationFailed = errors.New("authentication failed") + var ErrBodyTooLarge = errors.New("body too large") + var ErrFilter = errors.New("filter error") + var ErrInternal = errors.New("internal error") + var ErrInvalidSerializerConfig = errors.New("invalid serializer config") + var ErrMethodNotAllowed = errors.New("method not allowed") + var ErrNotAcceptable = errors.New("not acceptable") + var ErrNotFound = errors.New("not found") + var ErrPagination = errors.New("pagination error") + var ErrParse = errors.New("parse error") + var ErrPermissionDenied = errors.New("permission denied") + var ErrReverse = errors.New("reverse error") + var ErrRouteConflict = errors.New("route conflict") + var ErrThrottled = errors.New("request throttled") + var ErrUnsupportedMediaType = errors.New("unsupported media type") + var ErrUpload = errors.New("upload error") + var ErrValidation = errors.New("validation error") + var ErrVersion = errors.New("version error") + func CheckObjectPermissions(ctx context.Context, request *Request, object any, classes ...PermissionClass) error + func ImageSignatureValidator(file UploadedFile) error + func OrderedErrorKeys(errors map[string][]string) []string + type APIError struct + Code string + Fields map[string][]string + Message string + RequestID string + type APIMetadata struct + Actions []ActionMetadata + Authentication []string + BrowsableAPI bool + Filters FilterMetadata + Forms map[string][]SerializerFieldMetadata + Pagination string + Permissions []string + Routes []RouteMetadata + Serializer SerializerMetadata + Throttles []string + Version string + func BuildMetadata(request *Request, router *Router, options MetadataOptions) APIMetadata + type APIView struct + BodyLimit int64 + CheckAuthentication RequestHook + CheckPermissions RequestHook + CheckThrottles RequestHook + FinalizeResponse ResponseFinalizer + HandleException ExceptionHandler + Handler View + InitializeRequest RequestInitializer + ParseBody bool + ParserRegistry ParserRegistry + func (v APIView) AsView() View + type AcceptHeaderVersioning struct + Config VersioningConfig + func (v AcceptHeaderVersioning) ResolveVersion(request *Request) (string, error) + type ActionMetadata struct + Detail bool + Methods []string + Name string + type AuthenticationResult struct + Auth any + User auth.User + type Authenticator interface + Authenticate func(context.Context, *Request) (AuthenticationResult, bool, error) + func SessionAuthentication() Authenticator + func TokenAuthentication(store TokenStore) Authenticator + type AuthenticatorFunc func(context.Context, *Request) (AuthenticationResult, bool, error) + func (f AuthenticatorFunc) Authenticate(ctx context.Context, request *Request) (AuthenticationResult, bool, error) + type BrowsableAPIRenderer struct + func (BrowsableAPIRenderer) MediaType() string + func (BrowsableAPIRenderer) Render(value any) ([]byte, string, error) + type CursorPagination struct + CursorQueryParam string + MaxPageSize int + Ordering string + PageSize int + PageSizeQueryParam string + func (p CursorPagination) Paginate(request *Request, items []any) (PaginatedResult, error) + type ExceptionHandler func(context.Context, *Request, error) Response + type FieldOptions struct + AllowBlank bool + AllowNull bool + Default any + ErrorMessages map[string]string + HelpText string + Label string + ReadOnly bool + Required bool + Source string + Validators []FieldValidator + WriteOnly bool + type FieldValidator func(any) error + func UniqueValidator(check func(any) (bool, error)) FieldValidator + type FilterBackend interface + Filter func(context.Context, *Request, []map[string]any) ([]map[string]any, error) + type FilterBackendFunc func(context.Context, *Request, []map[string]any) ([]map[string]any, error) + func (f FilterBackendFunc) Filter(ctx context.Context, request *Request, rows []map[string]any) ([]map[string]any, error) + type FilterMetadata struct + Exact []string + Lookups map[string][]string + Ordering []string + Search []string + type FilterSet struct + Backends []FilterBackend + Distinct bool + DistinctFields []string + ExactFields []string + LookupFields map[string][]string + OrderingFields []string + OrderingParam string + SearchFields []string + SearchParam string + func (f FilterSet) Apply(ctx context.Context, request *Request, rows []map[string]any) ([]map[string]any, error) + type HostNameVersioning struct + Config VersioningConfig + func (v HostNameVersioning) ResolveVersion(request *Request) (string, error) + type JSONRenderer struct + func (JSONRenderer) MediaType() string + func (JSONRenderer) Render(value any) ([]byte, string, error) + type LimitOffsetPagination struct + DefaultLimit int + LimitParam string + MaxLimit int + OffsetParam string + func (p LimitOffsetPagination) Paginate(request *Request, items []any) (PaginatedResult, error) + type MemoryThrottleStore struct + func NewMemoryThrottleStore() *MemoryThrottleStore + func (s *MemoryThrottleStore) Hit(_ context.Context, key string, now time.Time, window time.Duration) (int, time.Time, error) + type MemoryTokenStore struct + func NewMemoryTokenStore(tokens ...Token) *MemoryTokenStore + func (s *MemoryTokenStore) Add(token Token) + func (s *MemoryTokenStore) FindToken(_ context.Context, key string) (Token, bool, error) + type MemoryUploadStorage struct + Contents map[string][]byte + Files []StoredUpload + func NewMemoryUploadStorage() *MemoryUploadStorage + func (s *MemoryUploadStorage) SaveUpload(_ context.Context, file UploadedFile) (StoredUpload, error) + type MetadataOptions struct + Authentication []string + FilterSet FilterSet + Pagination any + Permissions []string + Serializer *Serializer + Throttles []string + type MetadataViewSetStore struct + Model models.Metadata + Store *orm.MetadataStore + func NewMetadataViewSetStore(store *orm.MetadataStore, meta models.Metadata) MetadataViewSetStore + func (s MetadataViewSetStore) Create(ctx context.Context, _ *Request, data map[string]any) (map[string]any, error) + func (s MetadataViewSetStore) Destroy(ctx context.Context, _ *Request, lookup string) error + func (s MetadataViewSetStore) List(ctx context.Context, _ *Request) ([]map[string]any, error) + func (s MetadataViewSetStore) Retrieve(ctx context.Context, _ *Request, lookup string) (map[string]any, error) + func (s MetadataViewSetStore) Update(ctx context.Context, _ *Request, lookup string, data map[string]any, ...) (map[string]any, error) + type ModelSerializer struct + func NewModelSerializer(config ModelSerializerConfig) (*ModelSerializer, error) + func (s *ModelSerializer) Create(data map[string]any) (map[string]any, error) + func (s *ModelSerializer) FieldNames() []string + func (s *ModelSerializer) Render(instance map[string]any) map[string]any + func (s *ModelSerializer) Update(instance map[string]any, data map[string]any) (map[string]any, error) + func (s *ModelSerializer) Validate(input map[string]any) (map[string]any, map[string][]string, bool) + type ModelSerializerConfig struct + CreateFunc func(map[string]any) (map[string]any, error) + Depth int + Exclude []string + ExtraKwargs map[string]FieldOptions + Fields []string + Model models.Metadata + NestedSerializers map[string]*Serializer + ReadOnlyFields []string + UpdateFunc func(map[string]any, map[string]any) (map[string]any, error) + type ModelViewSet struct + Actions map[string]ViewSetAction + LookupParam string + Serializer *Serializer + Store ModelViewSetStore + View APIView + func (v *ModelViewSet) AsView(action string) View + func (v *ModelViewSet) Create(ctx context.Context, request *Request) Response + func (v *ModelViewSet) Destroy(ctx context.Context, request *Request) Response + func (v *ModelViewSet) List(ctx context.Context, request *Request) Response + func (v *ModelViewSet) PartialUpdate(ctx context.Context, request *Request) Response + func (v *ModelViewSet) RegisterAction(name string, action ViewSetAction) + func (v *ModelViewSet) Retrieve(ctx context.Context, request *Request) Response + func (v *ModelViewSet) Update(ctx context.Context, request *Request) Response + type ModelViewSetStore interface + Create func(context.Context, *Request, map[string]any) (map[string]any, error) + Destroy func(context.Context, *Request, string) error + List func(context.Context, *Request) ([]map[string]any, error) + Retrieve func(context.Context, *Request, string) (map[string]any, error) + Update func(context.Context, *Request, string, map[string]any, bool) (map[string]any, error) + type MultipartBody struct + Files map[string][]UploadedFile + Values map[string][]string + type NamespaceVersioning struct + Config VersioningConfig + Param string + func (v NamespaceVersioning) ResolveVersion(request *Request) (string, error) + type ObjectValidator func(map[string]any) ValidationErrors + func ModelValidationValidator(ctx context.Context, validators ...modelvalidation.Validator) ObjectValidator + func UniqueTogetherValidator(fields []string, check func(map[string]any) (bool, error)) ObjectValidator + type OpenAPIComponents struct + Responses map[string]any + Schemas map[string]any + SecuritySchemes map[string]map[string]any + type OpenAPIExternalDocs struct + URL string + type OpenAPIInfo struct + Title string + Version string + type OpenAPIMediaType struct + Schema map[string]any + type OpenAPIOperation struct + Description string + OperationID string + Parameters []OpenAPIParameter + RequestBody *OpenAPIRequestBody + Responses map[string]any + Security []map[string][]string + Summary string + Tags []string + type OpenAPIOptions struct + AdminDocsURL string + Authentication []string + Pagination any + Router *Router + Serializer *Serializer + Title string + Version string + type OpenAPIParameter struct + In string + Name string + Required bool + Schema map[string]any + type OpenAPIPathItem map[string]OpenAPIOperation + type OpenAPIRequestBody struct + Content map[string]OpenAPIMediaType + Required bool + type OpenAPISpec struct + Components OpenAPIComponents + ExternalDocs OpenAPIExternalDocs + Info OpenAPIInfo + OpenAPI string + Paths map[string]OpenAPIPathItem + Security []map[string][]string + func GenerateOpenAPI(options OpenAPIOptions) OpenAPISpec + type OperationMetadata struct + Description string + Responses map[int]ResponseSchema + Summary string + Tags []string + type OrderedFieldError struct + Field string + Messages []string + func OrderedFieldErrors(errors map[string][]string) []OrderedFieldError + type PageNumberPagination struct + MaxPageSize int + PageQueryParam string + PageSize int + PageSizeQueryParam string + func (p PageNumberPagination) Paginate(request *Request, items []any) (PaginatedResult, error) + type PaginatedResult struct + Count int + Next string + Previous string + Results []any + type Parser func(*http.Request, int64) (any, error) + type ParserRegistry struct + func DefaultParserRegistry() ParserRegistry + func (r ParserRegistry) Parse(request *http.Request, limit int64) (any, error) + type PermissionClass interface + HasObjectPermission func(context.Context, *Request, any) bool + HasPermission func(context.Context, *Request) bool + func AllowAny() PermissionClass + func CustomObjectPermission(check func(context.Context, *Request, any) bool) PermissionClass + func CustomPermission(check func(context.Context, *Request) bool) PermissionClass + func IsAdminUser() PermissionClass + func IsAuthenticated() PermissionClass + func IsAuthenticatedOrReadOnly() PermissionClass + func ModelPermissions(appLabel, model string) PermissionClass + type PlainTextRenderer struct + func (PlainTextRenderer) MediaType() string + func (PlainTextRenderer) Render(value any) ([]byte, string, error) + type QueryParameterVersioning struct + Config VersioningConfig + Param string + func (v QueryParameterVersioning) ResolveVersion(request *Request) (string, error) + type Rate struct + Limit int + Window time.Duration + func ParseRate(value string) (Rate, error) + type RateThrottle struct + Identity func(*Request) string + Now func() time.Time + Rate Rate + Scope string + Store ThrottleStore + func AnonymousRateThrottle(rate Rate, store ThrottleStore) *RateThrottle + func ScopedRateThrottle(scope string, rate Rate, store ThrottleStore) *RateThrottle + func UserRateThrottle(rate Rate, store ThrottleStore) *RateThrottle + func (t *RateThrottle) Allow(ctx context.Context, request *Request) (ThrottleDecision, error) + type Renderer interface + MediaType func() string + Render func(any) ([]byte, string, error) + func DefaultRenderers(enableBrowsable bool) []Renderer + func NegotiateRenderer(accept string, renderers []Renderer) (Renderer, error) + type Request struct + func NewRequest(raw *http.Request) *Request + func (r *Request) AcceptedRenderer() string + func (r *Request) Auth() any + func (r *Request) Method() string + func (r *Request) ParsedBody() any + func (r *Request) PathParam(name string) string + func (r *Request) QueryParam(name string) string + func (r *Request) Raw() *http.Request + func (r *Request) RemoteIP() string + func (r *Request) User() auth.User + func (r *Request) Version() string + func (r *Request) WithAcceptedRenderer(renderer string) *Request + func (r *Request) WithAuth(value any) *Request + func (r *Request) WithParsedBody(body any) *Request + func (r *Request) WithPathParam(name, value string) *Request + func (r *Request) WithUser(user auth.User) *Request + func (r *Request) WithVersion(version string) *Request + type RequestHook func(context.Context, *Request) error + func AuthenticateRequest(authenticators ...Authenticator) RequestHook + func CheckPermissions(classes ...PermissionClass) RequestHook + func CheckThrottles(throttles ...Throttle) RequestHook + func VersionRequest(strategy VersioningStrategy) RequestHook + type RequestInitializer func(context.Context, *Request) (*Request, error) + type Response struct + func Accepted(body any) Response + func Created(body any) Response + func DefaultExceptionHandler(_ context.Context, _ *Request, err error) Response + func Error(status int, err APIError) Response + func File(path, contentType string) Response + func JSON(status int, body any) Response + func NoContent() Response + func (r *Response) Header() http.Header + func (r Response) HTTP() frameworkhttp.Response + func (r Response) Write(w http.ResponseWriter) error + type ResponseFinalizer func(context.Context, *Request, Response) Response + type ResponseSchema struct + ContentType string + Description string + Schema map[string]any + type Route struct + Action string + Detail bool + HTTPHandler nethttp.Handler + Metadata OperationMetadata + Methods []string + Name string + Pattern string + View View + type RouteMetadata struct + Action string + Detail bool + Methods []string + Name string + Pattern string + type Router struct + func NewRouter(options ...RouterOption) *Router + func (r *Router) Handle(name, pattern string, view View, methods ...string) error + func (r *Router) HandleHTTP(name, pattern string, handler nethttp.Handler, metadata OperationMetadata, ...) error + func (r *Router) Include(prefix string, subrouter *Router) error + func (r *Router) MountHTTP(router *frameworkhttp.Router) error + func (r *Router) Register(prefix, basename string, viewset *ModelViewSet) error + func (r *Router) Resolve(ctx context.Context, request *Request) (response Response) + func (r *Router) Reverse(name string, args map[string]any) (string, error) + func (r *Router) Routes() []Route + func (r *Router) ServeHTTP(w nethttp.ResponseWriter, raw *nethttp.Request) + type RouterOption func(*Router) + func WithAPIPrefix(prefix string) RouterOption + func WithExceptionHandler(handler ExceptionHandler) RouterOption + func WithTrailingSlash(enabled bool) RouterOption + type Serializer struct + func NewSerializer(fields ...SerializerField) *Serializer + func (s *Serializer) Render(obj map[string]any) map[string]any + func (s *Serializer) Validate(input map[string]any) (map[string]any, map[string][]string, bool) + func (s *Serializer) ValidatePartial(input map[string]any) (map[string]any, map[string][]string, bool) + func (s *Serializer) WithObjectValidators(validators ...ObjectValidator) *Serializer + type SerializerField struct + Child *SerializerField + Choices []string + Kind string + MethodFunc func(map[string]any) any + Name string + Nested *Serializer + Options FieldOptions + func BooleanField(name string, options FieldOptions) SerializerField + func ChoiceField(name string, options FieldOptions, choices []string) SerializerField + func DateField(name string, options FieldOptions) SerializerField + func DateTimeField(name string, options FieldOptions) SerializerField + func DecimalField(name string, options FieldOptions) SerializerField + func DictField(name string, options FieldOptions) SerializerField + func DurationField(name string, options FieldOptions) SerializerField + func EmailField(name string, options FieldOptions) SerializerField + func FileField(name string, options FieldOptions) SerializerField + func FloatField(name string, options FieldOptions) SerializerField + func HyperlinkedRelatedField(name string, options FieldOptions) SerializerField + func ImageField(name string, options FieldOptions) SerializerField + func IntegerField(name string, options FieldOptions) SerializerField + func JSONField(name string, options FieldOptions) SerializerField + func ListField(name string, options FieldOptions, child SerializerField) SerializerField + func MethodField(name string, method func(map[string]any) any) SerializerField + func MultipleChoiceField(name string, options FieldOptions, choices []string) SerializerField + func NestedObjectField(name string, options FieldOptions, serializer *Serializer) SerializerField + func PrimaryKeyRelatedField(name string, options FieldOptions) SerializerField + func SlugField(name string, options FieldOptions) SerializerField + func SlugRelatedField(name string, options FieldOptions) SerializerField + func StringField(name string, options FieldOptions) SerializerField + func TimeField(name string, options FieldOptions) SerializerField + func URLField(name string, options FieldOptions) SerializerField + func UUIDField(name string, options FieldOptions) SerializerField + type SerializerFieldMetadata struct + Choices []string + HelpText string + Kind string + Label string + Name string + ReadOnly bool + Required bool + Source string + WriteOnly bool + type SerializerMetadata struct + Fields []SerializerFieldMetadata + func SerializerMetadataFor(serializer *Serializer) SerializerMetadata + type StoredUpload struct + ContentType string + Location string + Name string + Size int64 + type Throttle interface + Allow func(context.Context, *Request) (ThrottleDecision, error) + type ThrottleDecision struct + Allowed bool + Key string + RetryAfter time.Duration + Scope string + type ThrottleError struct + RetryAfter time.Duration + func (e *ThrottleError) Error() string + func (e *ThrottleError) Unwrap() error + type ThrottleStore interface + Hit func(context.Context, string, time.Time, time.Duration) (int, time.Time, error) + type Token struct + CreatedAt time.Time + Key string + User auth.User + UserID int64 + func (Token) ModelMeta() models.Metadata + type TokenStore interface + FindToken func(context.Context, string) (Token, bool, error) + type URLPathVersioning struct + Config VersioningConfig + func (v URLPathVersioning) ResolveVersion(request *Request) (string, error) + type UploadConfig struct + AllowedExtensions []string + FieldName string + ImageValidator func(UploadedFile) error + MaxSize int64 + Storage UploadStorage + type UploadHandler struct + Config UploadConfig + func (h UploadHandler) HandleMultipart(ctx context.Context, request *Request) ([]StoredUpload, error) + func (h UploadHandler) HandleStream(ctx context.Context, request *Request, filename string) (StoredUpload, error) + func (h UploadHandler) SaveUploadedFile(ctx context.Context, file UploadedFile) (StoredUpload, error) + type UploadStorage interface + SaveUpload func(context.Context, UploadedFile) (StoredUpload, error) + type UploadedFile struct + Content []byte + Filename string + Size int64 + type ValidationErrors map[string][]string + func FromModelValidationError(err error) ValidationErrors + func (e ValidationErrors) Add(field, message string) + type VersioningConfig struct + AllowedVersions []string + DefaultVersion string + type VersioningStrategy interface + ResolveVersion func(*Request) (string, error) + type View func(context.Context, *Request) Response + func FunctionView(handler View) View + func OpenAPIJSONView(spec OpenAPISpec) View + type ViewSetAction struct + Detail bool + Handler View + Methods []string