routed_http 0.1.3 copy "routed_http: ^0.1.3" to clipboard
routed_http: ^0.1.3 copied to clipboard

HTTP utilities for Routed — binding, multipart, negotiation, SSE and conditional requests.

routed_http #

HTTP utilities for Routed: request binding, multipart parsing, content negotiation, response compression, Server-Sent Events, and conditional requests.

Install #

dependencies:
  routed_core: ^0.5.0
  routed_http: ^0.1.2

Import package:routed_http/routed_http.dart to add the HTTP extensions to EngineContext:

import 'dart:async';

import 'package:routed_core/routed_core.dart';
import 'package:routed_http/routed_http.dart';

Future<void> main() async {
  final engine = await Engine.create(providers: Engine.defaultProviders)
    ..get('/events', (ctx) async {
      await ctx.sse(
        Stream.value(SseEvent(data: '{"status":"ready"}')),
      );
    });

  await engine.serve(port: 8080);
}

The package includes JSON, XML, form, query, URI, and multipart bindings; binding extensions such as ctx.bind(...), ctx.bindJSON(...), and ctx.bindQuery(...); content negotiation; ETag and conditional-request helpers; SSE encoding/streaming; and an opt-in gzip provider for buffered responses.

XML request bodies are selected automatically for application/xml and text/xml. They bind to the same map or Bindable targets as the other body bindings, preserving the document root, attributes under @attributes, and text under #text.

To use compression directly from this package, pass an immutable typed configuration to the provider:

final engine = await Engine.create(
  providers: [
    ...Engine.defaultProviders,
    RoutedCompressionProvider(
      CompressionConfig(enabled: true, minLength: 1),
    ),
  ],
);

Provider configuration is assembled in Dart before startup. There is no YAML or dotted-key configuration path for compression, and changing a provider's configuration requires creating a new engine.

Use routed_http directly when you need these utilities without importing the full routed facade. The facade re-exports the package for batteries-included applications.

0
likes
130
points
743
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

HTTP utilities for Routed — binding, multipart, negotiation, SSE and conditional requests.

Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

collection, file, http_parser, meta, mime, routed_core, xml

More

Packages that depend on routed_http