http_sfv 0.1.0 copy "http_sfv: ^0.1.0" to clipboard
http_sfv: ^0.1.0 copied to clipboard

Dart implementation of Structured Field Values for HTTP (RFC8941)

http_sfv (Structured Field Values) #

A Dart implementation of the Structured Field Values for HTTP (RFC 8941) specification.

Usage #

Use StructuredFieldValue.decode to parse a header string into a structured field value.

import 'package:http_sfv/http_sfv.dart';

void main() {
  const header = '"foo";bar;baz=tok, (foo bar);bat';
  final decoded = StructuredFieldValue.decode(
    header,
    type: StructuredFieldValueType.list,
  );
  print(decoded);
  // Prints: List(Item(foo, bar: true, baz: tok), InnerList([Item(foo), Item(bar)], bat: true))
}

Use StructuredFieldValue.encode to convert a structured field value to a header string.

import 'package:http_sfv/http_sfv.dart';

void main() {
  final dictionary = StructuredFieldDictionary({
    'a': false,
    'b': true,
    'c': StructuredFieldItem(
      true,
      parameters: {
        'foo': 'bar',
      },
    ),
  });
  print(dictionary.encode()); 
  // Prints: "a=?0, b, c;foo=bar"
}
0
likes
160
points
141
downloads

Publisher

verified publishercelest.dev

Weekly Downloads

Dart implementation of Structured Field Values for HTTP (RFC8941)

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-2-Clause-Patent (license)

Dependencies

collection, meta, source_span

More

Packages that depend on http_sfv