Skip to content
pubscout

coap

9.2.1, released 7 months ago by darticulate.com

A CoAP (Constrained Application Protocol) library providing an IPv4/v6 client in Dart.

$ flutter pub add coap
Source repository

What it does

It implements the Constrained Application Protocol (CoAP) for resource-constrained networks and nodes. It provides a CoAP client supporting UDP, observe resources, block-wise transfers, and custom methods like FETCH and PATCH.

AI-written summary of version 9.2.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to communicate with IoT devices using the CoAP protocol.
  • You need support for CoAP over UDP, block-wise transfers, or observing resources.

Skip it when

  • You are communicating with standard REST APIs over HTTP or HTTPS.
  • You require robust background connectivity without manually managing app lifecycle states.

Strengths

  • Full implementation of an IPv4/6 CoAP client with RFC compliance.
  • Supports advanced features like block-wise transfers, observe resources, and multicast over UDP.

Weaknesses

  • Futures may not survive when the app runs in the background or screen is off without manual lifecycle handling.
  • DTLS support is experimental and requires shipping OpenSSL binaries for platforms like iOS and Windows.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
12

Requires adding dependencies and running build_runner to generate the configuration class from a YAML file. DTLS usage requires native OpenSSL binaries on certain platforms.

FutureOr<void> main() async {
  final conf = CoapConfig();
  final baseUri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
  final client = CoapClient(baseUri, conf);

  try {
    final response =
        await client.get('multi-format', accept: CoapMediaType.textPlain);
    print('/multi-format response payload: ${response.payloadString}');
  } on Exception catch (e) {
    print('CoAP encountered an exception: $e');
  }

  client.close();
}

Alternatives

Packages that do the same job and could replace coap.

  • mqtt5_client

    A server and browser based MQTT Version 5 client for Dart supporting TCP and WebSockets.

  • mqtt_client

    A Dart MQTT client supporting TCP, WebSocket, secure connections and all QoS levels.

  • http2

    An HTTP/2 implementation in Dart for low-level transport and pooled HTTP/2 requests.

  • talker_dio_logger

    A lightweight, customizable logger for Dio HTTP client built on Talker.

Works with

Packages commonly used together with coap: ones it builds on, ones built on it, and its own family.