Here’s the latest in all things Aqueduct for Dart. Aqueduct 2.2 is now available on pub. This release’s primary focus is on request and response bodies.

Request bodies can now be bound to HTTPController variables:

class ThingController extends HTTPController {
  @httpPost
  Future<Response> createThing(@HTTPBody() Thing thing) async {
    var query = new Query<Thing>()..values = thing;

    return new Response.ok(await query.insert());
  }
}

A response body can now be a Streamthe response is sent once the stream is done:

class Controller extends HTTPController {
  @httpGet
  Future<Response> getFile() async {
    var file = new File("somefile.txt");
    var stream = file.openRead();

    return new Response.ok(stream);
  }
}

HTTPCodecRepository manages a collection of encoders and decoders associated with the content-type of a request or response.

HTTPCodecRepository.add(
  new ContentType("application", "xml"),
  const XMLCodec(),
  allowCompression: true);

The new HTTPFileController can serve files and control caching based on file extension:

@override
void setupRouter(Router router) {
  var fileController = new HTTPFileController("web/build/")
    ..addCachePolicy(new HTTPCachePolicy(), (p) => p.endsWith(".css"));
  router.route("/files/*").pipe(fileController);
}

See the full CHANGELOG.

 

Joe Conway

CEO & Founder at Stable Kernel

Leave a Reply

Your email address will not be published. Required fields are marked *