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)

example/http_sfv_example.dart

import 'package:http_sfv/http_sfv.dart';

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

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

  final list = StructuredFieldList([
    StructuredFieldItem(
      'foo',
      parameters: {
        'bar': true,
        'baz': Token('tok'),
      },
    ),
    StructuredFieldInnerList(
      [Token('foo'), Token('bar')],
      parameters: {
        'bat': true,
      },
    ),
  ]);
  print(decoded == list);
  // Prints: true
}
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