uri 0.11.3+1

  • Readme
  • Changelog
  • Installing
  • 74

Build Status

Utilities for working with URIs in Dart, mostly parsing and generating URIs.

UriPattern #

UriPattern is an interface for classes that match and parse URIs, much like the Pattern is for Strings. It defines the methods bool matches(Uri uri) and UriMatch match(Uri uri).

UriMatch #

UriMatch is the result of UriPattern.match(). It contains the parameters parsed out of a URI and the "rest" of the URI left over after parsing, which is useful for parsing a single URI with multiple relative URI patterns that form a hierarchy.

UriTemplate #

UriTemplate is an implementation of RFC 6570 URI Templates. URI Templates are useful for generating URIs from data. UriTemplates are created from a template string, and then expanded with data to generate a URI:

var template = new UriTemplate("http://example.com/~{user}/");
String fredUri = template.expand({'user': 'fred'});
print(fredUri); // prints: http://example.com/~fred/

Syntax #

URI templates are strings made up of fixed and variable parts. The variable parts are described with expressions, which are places within single curly-braces: { and }.

Expressions consist of an optional operator and a comma-separated list of variable_specifications. Variable specifications consist of a variable name and an optional modifier. The operator applies to the whole expression and controls how reserved characters are expanded, the prefix and separator, if any, applied to the expansion, and whether to expand the variable as a key/value pair. Modifiers apply to each variable in the expression and allow truncating the value, or "exploding" list and maps into multiple key/value pairs.

Examples #

  • http://example.com/~{username}/
  • http://example.com/dictionary/{term:1}/{term}
  • http://example.com/search{?q,lang}

Operators #

URI template expansions does more than simple variable replacement, it has facilities for generating paths, fragments, query strings and more. To control the expansion, expressions can use one of the supported operators:

noneSimple string expansion
+Reserved string expansion
#Fragment expansion
.Label expansion, dot-prefixed
/Path segments, slash-prefixed
;Path-style parameters, semicolon-prefixed
?Form-style query, ampersand-separated
&Form-style query continuation

Modifiers #

Modifiers control

noneDefault expansion
:nPrefix: use only the first n characters o the value
*"Explode" the lists and maps into key/value pairs

UriParser #

UriParser parses URIs according to a UriTemplate, extracting paramaters based on the variables defined in the template.

Since URI Templates are not designed to be parsable, only a restricted subset of templates can be used for parsing.

Parsable templates have the following restrictions over expandable templates:

  • URI components must come in order: scheme, host, path, query, fragment. There can only be one of each component.
  • Path expressions can only contain one variable.
  • Multiple expressions must be separated by a literal.
  • Only the following operators are supported: none, +, #, ?, &
  • Default and + operators are not allowed in query or fragment components.
  • Queries can only use the ? or & operator.
  • The ? operator can only be used once.
  • Fragments can only use the # operator

UriBuilder #

UriBuilder is mutable container of URI components for incrementally building Uris.

0.11.3+1 #

  • Updated project requirement to match flutter 2.0.0+

0.11.3 #

  • Change upper bound to 3.0.0.
  • Fix runtime type errors in tests.

0.11.2 #

  • Support the latest release of package:quiver.
  • Strong-mode clean.
  • Require at least Dart 2.0.0-dev.18.

0.11.1 #

  • Widen dependency on package:quiver

0.10.0 #

  • Migrate from the unittest to the new test package.

0.9.5 #

  • Widen dependency on quiver
  • Widen dependency on matcher

0.9.2 #

  • Preserve query parameters in UriMatch.rest

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  uri: ^0.11.3+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:uri/uri.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/src/uri_template.dart. (-15.25 points)

Analysis of lib/src/uri_template.dart reported 33 hints, including:

line 16 col 20: Unnecessary new keyword.

line 21 col 26: Unnecessary new keyword.

line 22 col 23: Unnecessary new keyword.

line 23 col 31: Unnecessary new keyword.

line 25 col 1: Prefer using /// for doc comments.

Fix lib/matchers.dart. (-7.71 points)

Analysis of lib/matchers.dart reported 16 hints, including:

line 10 col 1: Prefer using /// for doc comments.

line 16 col 18: Use = to separate a named parameter from its default value.

line 17 col 13: Use = to separate a named parameter from its default value.

line 18 col 13: Use = to separate a named parameter from its default value.

line 19 col 13: Use = to separate a named parameter from its default value.

Fix lib/src/uri_pattern.dart. (-4.41 points)

Analysis of lib/src/uri_pattern.dart reported 9 hints, including:

line 10 col 1: Prefer using /// for doc comments.

line 14 col 3: Prefer using /// for doc comments.

line 19 col 3: Prefer using /// for doc comments.

line 25 col 3: Prefer using /// for doc comments.

line 31 col 1: Prefer using /// for doc comments.

Fix lib/src/encoding.dart. (-2.96 points)

Analysis of lib/src/encoding.dart reported 6 hints, including:

line 22 col 25: Avoid const keyword.

line 42 col 23: Avoid const keyword.

line 61 col 1: Prefer using /// for doc comments.

line 70 col 27: Use = to separate a named parameter from its default value.

line 90 col 16: Unnecessary new keyword.

Fix lib/src/uri_builder.dart. (-1.49 points)

Analysis of lib/src/uri_builder.dart reported 3 hints:

line 7 col 1: Prefer using /// for doc comments.

line 31 col 27: Unnecessary new keyword.

line 35 col 18: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-37.81 points)

The package was last published 71 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and uri.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68 <3.0.0
matcher >=0.12.0 <0.13.0 0.12.6
quiver >=2.0.0 <3.0.0 2.1.2+1
utf >=0.8.10 <=0.10.0 0.9.0+5
Transitive dependencies
meta 1.1.8
path 1.6.4
stack_trace 1.9.3
Dev dependencies
build_runner ^0.10.0
build_test ^0.10.2
build_web_compilers ^0.4.0
test >=0.12.0 <=1.3.0