astra library
Astra Framework
A modern, type-safe web framework for Dart inspired by FastAPI.
Classes
- AstraApp
- The main entry point for an Astra application.
- AstraLogger
- Abstract Logger Interface
- AuthService
- Abstract Auth Service
- Body
- Annotation for Request Body
- CacheManager
- Abstract Interface for Caching
- ConsoleLogger
- Default Console Logger
- Container
- A simple Dependency Injection Container.
- Context
- Context encapsulates the current HTTP request and response building utilities.
- Controller
- Annotation for Controllers
- DatabaseConnection
- Abstract Interface for Database Connection
- Delete
- Annotation for HTTP DELETE requests
- FileLogger
- Simple File Logger
- Get
- Annotation for HTTP GET requests
- HttpMethodAnnotation
- Base class for HTTP methods
- InMemoryCache
- InMemory Cache Implementation (Default)
- OpenApiDocument
- OpenApiInfo
- OpenApiOperation
- OpenApiParameter
- OpenApiRegistry
- Patch
- Annotation for HTTP PATCH requests
- Path
- Annotation for Path Parameters
- Post
- Annotation for HTTP POST requests
- Put
- Annotation for HTTP PUT requests
- Query
- Annotation for Query Parameters
- Request
- An HTTP request to be processed by a Shelf application.
- Response
- The response returned by a Handler.
- RouteResult
- SimpleAuthService
-
SIMULATED JWT Implementation (For Demo purposes without external deps)
In production, replace with
dart_jsonwebtoken. - TrieNode
- A simple Radix Trie node for routing.
- TrieRouter
- UserPrincipal
- User Principal object
- WebSocketChannel
-
A
StreamChannelthat communicates over a WebSocket. - WebSocketRoute
- Annotation for WebSocket routes
- WebSocketSink
- The sink exposed by a WebSocketChannel.
Extensions
Functions
-
authMiddleware(
AuthService authService, {bool optional = false, List< String> whitelist = const []}) → Middleware -
Middleware that protects routes
Adds 'user' to context if valid.
Returns 401 if
optionalis false and token is missing/invalid.whitelistis a list of paths that should be excluded from auth checks (e.g.'/login', '/docs'). -
requestLogger(
AstraLogger logger) → Middleware -
Middleware that logs requests using the provided
logger. -
webSocketHandler(
ConnectionCallback onConnection, {Iterable< String> ? protocols, Iterable<String> ? allowedOrigins, Duration? pingInterval}) → Handler - Creates a Shelf handler that upgrades HTTP requests to WebSocket connections.
Exceptions / Errors
- AstraHttpException
- Base exception class for Astra HTTP errors.
- BadRequestException
- 400 Bad Request
- ForbiddenException
- 403 Forbidden
- NotFoundException
- 404 Not Found
- 401 Unauthorized
- WebSocketChannelException
- An exception thrown by a WebSocketChannel.