fluri 1.2.3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 91

fluri

Pub Build Status codecov.io documentation

Examples/Usage

Fluri is a fluent URI library for Dart built to make URI mutation easy.

The dart:core.Uri class provides an immutable representation of URIs, which makes it difficult to incrementally build them or update them at a later time. If you wanted to build a long URI from the individual pieces, you would do something like this:

Uri uri = new Uri(
  scheme: 'https',
  host: 'example.com',
  path: 'path/to/resource'
);

If you later wanted to update the path and add a query parameter, you'd have to do this:

uri = uri.replace(
  path: 'new/path',
  query: 'foo=true'
);

Now let's say you want update the query without losing what you already have:

Map query = new Map.from(uri.queryParameters);
query['bar'] = '10';
uri = uri.replace(queryParameters: query);

As you can see, incremental or fluent-style URI mutations become a hassle with the core Uri class.

With fluri, the above interactions are easy:

import 'package:fluri/fluri.dart';

Fluri fluri = new Fluri()
  ..scheme = 'https'
  ..host = 'example.com'
  ..path = 'path/to/resource';

fluri
  ..path = 'new/path'
  ..query = 'foo=true';

fluri.updateQuery({'bar': '10'});

Additional methods like appendToPath and setQueryParam make it easy to build on top of a base URL:

import 'package:fluri/fluri.dart';

Fluri base = new Fluri('https://example.com/base/');

Fluri fluri = new Fluri.from(base)
  ..appendToPath('path/to/resource')
  ..setQueryParam('count', '10');

Fluri also supports multi-value parameters. To access the query parameters as Map<String, List<String>>, use queryParametersAll (just like the Uri class):

var fluri = new Fluri('/resource?format=json&format=text');
print(fluri.queryParameters); // {'format': 'text'}
print(fluri.queryParametersAll); // {'format': ['json', 'text']}

To set a single query parameter to multiple values:

var fluri = new Fluri('/resource');
fluri.setQueryParam('format', ['json', 'text']);
print(fluri.queryParametersAll); // {'format': ['json', 'text']}

Using setQueryParam will always replace existing values:

var fluri = new Fluri('/resource');
fluri.setQueryParam('format', ['json', 'text']);
fluri.setQueryParam('format', ['binary', 'text']);
print(fluri.queryParametersAll); // {'format': ['binary', 'text']}

You can use the queryParametersAll setter to set the entire query with multi-value param support:

var fluri = new Fluri('/resource');
fluri.queryParametersAll = {'format': ['json', 'text'], 'count': ['5']}
print(fluri.queryParametersAll); // {'format': ['json', 'text'], 'count': ['5']}

Again, if you need to preserve existing query parameters, you can use the updateQuery method to do so. Set mergeValues: true and any values that you provide will be merged with existing values:

var fluri = new Fluri('/resource?format=json');
fluri.updateQuery({'format': ['binary', 'text'], 'count': '5'}, mergeValues: true);
print(fluri.queryParametersAll); // {'format': ['binary', 'json', 'text'], 'count': ['5']}

Dart SDK

As of version 1.2.0 of the fluri package, the minimum required Dart SDK version is 1.15.0.

Versioning and Stability

This library follows semver to the best of our interpretation of it. We want this library to be a stable dependency that’s easy to keep current. A good explanation of the versioning scheme that we intend to follow can be seen here from React.js:

https://facebook.github.io/react/blog/2016/02/19/new-versioning-scheme.html

In short: our goal is for every major release to be backwards compatible with the previous major version, giving consumers a lifespan of two major versions to deal with deprecations.

Development

This project leverages the dart_dev package for most of its tooling needs, including static analysis, code formatting, running tests, collecting coverage, and serving examples. Check out the dart_dev readme for more information.

Changelog

1.2.0

  • Feature: Support for multi-value parameters.

    See the [readme][https://github.com/Workiva/fluri/blob/master/README.md] for usage examples.

  • Dart SDK: In order to support multi-value parameters, the minimum required Dart SDK version is now 1.15.0 since that is when the queryParametersAll field was added to the Uri class.

1.1.1

  • Bug Fix: FluriMixin now defaults to an empty URI when uri is set to null.

1.1.0

New Features:

  • appendToPath(path) - append a path literal to the current path.
  • addPathSegment(segment) - add a single path segment to the current path.
  • setQueryParam(param, value) - set a single query parameter.
  • Fluri.from(other) - construct a Fluri instance from another.
  • Fluri.fromUri(uri) - construct a Fluri instance from a Uri instance.

1.0.1

No source changes in this release.

  • Add code coverage reporting.
  • Minor fixes and improvements to the readme.
  • Code formatting improvements thanks to dartfmt.

1.0.0

  • Initial version of Fluri: a fluent URI library for Dart built to make URI mutation easy.

1. Depend on it

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


dependencies:
  fluri: "^1.2.3"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:fluri/fluri.dart';
        
Version Uploaded Documentation Archive
1.2.3 Jul 5, 2017 Go to the documentation of fluri 1.2.3 Download fluri 1.2.3 archive
1.2.2 Jun 14, 2017 Go to the documentation of fluri 1.2.2 Download fluri 1.2.2 archive
1.2.1 Nov 8, 2016 Go to the documentation of fluri 1.2.1 Download fluri 1.2.1 archive
1.2.0 Nov 7, 2016 Go to the documentation of fluri 1.2.0 Download fluri 1.2.0 archive
1.1.1 Jan 6, 2016 Go to the documentation of fluri 1.1.1 Download fluri 1.1.1 archive
1.1.0 Dec 9, 2015 Go to the documentation of fluri 1.1.0 Download fluri 1.1.0 archive
1.0.1 Jun 11, 2015 Go to the documentation of fluri 1.0.1 Download fluri 1.0.1 archive
1.0.0 Apr 29, 2015 Go to the documentation of fluri 1.0.0 Download fluri 1.0.0 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
82 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
91

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:fluri/fluri.dart.

Suggestions

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use fluri.dart.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <2.0.0
Dev dependencies
coverage ^0.7.2
dart_dev ^1.7.6
dart_style ^1.0.6
dartdoc >=0.9.0 <0.13.0
test ^0.12.0