dox_core
The core of the Dox framework: HTTP server, router, requests, responses, DTO input, cache, storage and config.
Part of Dox, a web backend framework for Dart, like Laravel. Source code: github.com/dartondox/dox.
Install
The easy way is the dox CLI. It makes a full starter project:
dart pub global activate dox ^3.0.0-alpha
dox create my_app
To add the package to your own project:
dart pub add dox_core
Dox 3.x is in alpha (3.0.0-alpha.x). The API can still change before the stable release.
Use it
A full app with one route:
import 'package:dox_core/dox_core.dart';
class ApiRouter extends Router {
@override
String get prefix => 'api';
@override
void register() {
Route.get('/ping', (DoxRequest req) => 'pong'); // GET /api/ping
}
}
void main() async {
Dox().initialize(AppConfig(
appKey: Env.get('APP_KEY'), // read from .env
serverPort: 3000,
routers: <Router>[ApiRouter()],
));
await Dox().startServer();
}
Run it with dart run bin/server.dart, then call curl localhost:3000/api/ping.
A controller can ask for a typed, checked input class (a DTO):
@Dto()
class CreateBlog {
@Length(min: 3, max: 200)
final String title;
const CreateBlog({required this.title});
static const DtoSchema<CreateBlog> schema = $CreateBlogDto;
}
class BlogController {
Future<Blog> store(CreateBlog body) async { ... } // bad input gets 422
}
The DTO code is generated by dox_builder (dart run build_runner build).
Features
- One isolate per CPU core. All isolates serve the same port.
- A native HTTP server by default (
dox_http_native). Setserver: ServerBackend.dartIoto usedart:io. - Router with groups, middleware, typed path params and resource routes.
- DTO input: Dox reads the body or query, checks it, and answers
422with all errors. Cache()(fromdox_cache) andStorage()(fromdox_storage).- OpenAPI docs at
/docs(fromdox_openapi). Off in production by default. - Optional Socket.IO on the same port (from
dox_socketio). - Typed env class, CORS, cookies, hashing and encryption.
Documentation
License
MIT. See LICENSE.
Libraries
- app
- cache/cache
- constants/constants
- constants/http_request_method
- dox_core
- env/env
- env/env_reader
- exception/bad_request_exception
- exception/internal_error_exception
- exception/not_found_exception
- exception/payload_too_large_exception
- exception/query_exception
- exception/validation_exception
- http/http_controller_handler
- http/http_cors_handler
- http/http_error_handler
- http/http_request_handler
- http/http_response_handler
- http/http_route_handler
- http/http_websocket_handler
- http/request/dox_request
- http/request/form_data_visitor
- http/request/form_input
- http/request/http_request_body
- http/request/request_file
- http/request/trusted_proxy
- http/response/dox_response
- http/response/serializer
- interfaces/app_config
- coverage:ignore-file
- interfaces/dox_service
- coverage:ignore-file
- interfaces/response_handler_interface
- interfaces/router
- ioc/ioc_container
- isolate/dox_isolate
- isolate/isolate_handler
- isolate/isolate_interfaces
- middleware/log_middleware
- openapi/openapi_config
- openapi/openapi_document
- openapi/openapi_route_reader
- router/route
- router/route_data
- server/dox_server
- socketio/socket_io_config
- storage/storage
- storage/storage_config
- storage/storage_file_controller
- utils/aes_encryptor
- utils/extensions
- utils/extensions/num
- utils/hash
- utils/json
- utils/logger
- coverage:ignore-file
- utils/utils
- validation/request_validator