dox_core

The core of the Dox framework: HTTP server, router, requests, responses, DTO input, cache and config.

pub package license: MIT

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 (dox_http_native): Rust parses HTTP and speaks WebSocket, your code stays in Dart.
  • Router with groups, middleware, typed path params and resource routes.
  • DTO input: Dox reads the body or query, checks it, and answers 422 with all errors.
  • Cache() (from dox_cache). For Storage(), add the dox_storage package.
  • OpenAPI docs at /docs (from dox_openapi). Off in production by default.
  • Socket.IO on the same port: add the dox_socketio package.
  • 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/exception_handler
exception/internal_error_exception
exception/not_found_exception
exception/payload_too_large_exception
exception/query_exception
exception/token_mismatch_exception
exception/too_many_requests_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/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
http/response/stream_file
interfaces/app_config
coverage:ignore-file
interfaces/dox_service
coverage:ignore-file
interfaces/next_middleware
interfaces/response_handler_interface
interfaces/router
ioc/ioc_container
isolate/dox_isolate
isolate/isolate_handler
isolate/isolate_interfaces
middleware/health_check
middleware/log_middleware
middleware/rate_limit
middleware/security_headers
openapi/openapi_config
openapi/openapi_document
openapi/openapi_route_reader
router/route
router/route_data
server/dox_server
session/session
session/session_config
session/session_middleware
testing
Helpers for app tests: a client that calls your routes, and checks for the answers.
testing/dox_test_client
testing/test_response
utils/aes_encryptor
utils/extensions
utils/extensions/num
utils/hash
utils/json
utils/logger
coverage:ignore-file
utils/path_pattern
utils/utils
validation/request_validator