aws_common 0.7.4 copy "aws_common: ^0.7.4" to clipboard
aws_common: ^0.7.4 copied to clipboard

Common types and utilities used across AWS and Amplify packages.

example/aws_common_example.dart

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'dart:convert';

import 'package:aws_common/aws_common.dart';

class LoggingClient extends AWSBaseHttpClient {
  static final _logger = AWSLogger().createChild('HTTP');

  Future<void> _logRequest(AWSBaseHttpRequest request) async {
    final sb = StringBuffer()
      ..write(request.method.value)
      ..write(' ')
      ..writeln(request.uri)
      ..write(await utf8.decodeStream(request.split()));
    _logger.debug(sb.toString());
  }

  Future<void> _logResponse(AWSBaseHttpResponse response) async {
    final sb = StringBuffer()
      ..writeln(response.statusCode)
      ..write(await utf8.decodeStream(response.split()));
    _logger.debug(sb.toString());
  }

  @override
  Future<AWSBaseHttpRequest> transformRequest(
    AWSBaseHttpRequest request,
  ) async {
    await _logRequest(request);
    return request;
  }

  @override
  Future<AWSBaseHttpResponse> transformResponse(
    AWSBaseHttpResponse response,
  ) async {
    await _logResponse(response);
    return response;
  }
}

// Prints:
// ```
// DEBUG | HTTP       | POST https://httpstat.us/200?
// Hello, world
// DEBUG | HTTP       | 200
// 200 OK
// ```
Future<void> main() async {
  AWSLogger().logLevel = LogLevel.debug;

  final client = LoggingClient();
  final request = AWSHttpRequest.post(
    Uri.parse('https://httpstat.us/200'),
    body: 'Hello, world'.codeUnits,
  );
  await client.send(request).response;
  await client.close();
}
1
likes
150
points
83k
downloads

Publisher

verified publisheraws-amplify.com

Weekly Downloads

Common types and utilities used across AWS and Amplify packages.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

async, built_collection, built_value, collection, http2, js, json_annotation, logging, meta, mime, os_detect, path, stream_transform, uuid

More

Packages that depend on aws_common