dox_core 3.0.0-alpha.6
dox_core: ^3.0.0-alpha.6 copied to clipboard
A perfect solution for your web backend development with dart that offers a wide range of features to help you build powerful and scalable web applications.
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.