Viewing version 2.0.3. Open the latest package page.
fluri
2.0.3Fluri is a fluent URI library built to make URI mutation easy.
Readme
fluri
Pub Build Status 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:
var uri = 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:
var query = 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';
var fluri = 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';
var base = Fluri('https://example.com/base/');
var fluri = 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 = 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 = Fluri('/resource');
fluri.setQueryParam('format', ['json', 'text']);
print(fluri.queryParametersAll); // {'format': ['json', 'text']}
Using setQueryParam will always replace existing values:
var fluri = 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 = 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 = Fluri('/resource?format=json');
fluri.updateQuery({'format': ['binary', 'text'], 'count': '5'}, mergeValues: true);
print(fluri.queryParametersAll); // {'format': ['binary', 'json', 'text'], 'count': ['5']}
Changelog
Changelog
2.0.0
- Stable null safe release.
1.3.0
- Add a
removeQueryParam()method.
1.2.8
- Readme updates.
1.2.7
- Readme updates.
1.2.6
- Drop Dart 1 support.
1.2.5
- Improvement: Dart 2 compatible! CI now runs on Dart 2 stable and Dart 1.
1.2.4
-
Improvement: Initial Dart 2 and DDC compatibility changes.
-
Documentation: Add a
CODEOWNERSfile.
1.2.3
- Tech Debt: Update some dependency ranges for DDC compatibility.
1.2.2
- Tech Debt: Add and address lints.
1.2.1
-
Bug Fix: Calling
.appendToPath()will check for and prevent double slashes when joining the current path with the additional path. -
Documentation: Add GitHub Issue and Pull Request templates.
1.2.0
-
Feature: Support for multi-value parameters.
-
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
queryParametersAllfield was added to theUriclass.
1.1.1
- Bug Fix:
FluriMixinnow defaults to an empty URI whenuriis 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 aFluriinstance from another.Fluri.fromUri(uri)- construct aFluriinstance from aUriinstance.
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.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'fluri:2.0.3'pubspec.yaml
name: fluri
version: 2.0.3
description: Fluri is a fluent URI library built to make URI mutation easy.
homepage: https://github.com/Workiva/fluri
environment:
sdk: '>=2.12.0 <3.0.0'
dev_dependencies:
test: ^1.15.7
workiva_analysis_options: ^1.1.0
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | Cached · Upstream SHA-256 matched | Download | 5d57ff7e…19002b |
| 1.0.1 | Cached · Upstream SHA-256 matched | Download | d075ff41…eed076 |
| 1.1.0 | Cached · Upstream SHA-256 matched | Download | 617a5c6f…cfa2f8 |
| 1.1.1 | Cached · Upstream SHA-256 matched | Download | 4a9f040b…90b9d1 |
| 1.2.0 | Cached · Upstream SHA-256 matched | Download | 421fda9e…39348c |
| 1.2.1 | Cached · Upstream SHA-256 matched | Download | f9a987bd…0f1e8a |
| 1.2.2 | Cached · Upstream SHA-256 matched | Download | 1a0b4419…ff38e6 |
| 1.2.3 | Cached · Upstream SHA-256 matched | Download | 1145c603…e882c2 |
| 1.2.4 | Cached · Upstream SHA-256 matched | Download | 0492d70b…30b0a3 |
| 1.2.5 | Cached · Upstream SHA-256 matched | Download | 0e7c5b47…9f17be |
| 1.2.6 | Cached · Upstream SHA-256 matched | Download | 3f6230a0…58951d |
| 1.2.7 | Cached · Upstream SHA-256 matched | Download | 8a0326fc…25f8a8 |
| 1.2.8 | Cached · Upstream SHA-256 matched | Download | a9c90b44…f99923 |
| 1.3.0 | Cached · Upstream SHA-256 matched | Download | 3dade143…fe94b3 |
| 2.0.0 | Cached · Upstream SHA-256 matched | Download | 0a4d784e…88540a |
| 2.0.1 | Cached · Upstream SHA-256 matched | Download | 895884da…f0febc |
| 2.0.2 | Cached · Upstream SHA-256 matched | Download | e58c9bf5…9f828f |
| 2.0.3 | Cached · Upstream SHA-256 matched | Download | 16593549…614dc8 |
| 2.0.4 | Cached · Upstream SHA-256 matched | Download | 0715ffdf…1cc48f |
| 2.0.5 | Cached · Upstream SHA-256 matched | Download | a6151890…2cdd1e |
| 2.0.6 | Cached · Upstream SHA-256 matched | Download | 186cd173…638a80 |
Dependencies
No direct dependencies declared.