Provides a small library for Shelf to decouple producers of path parameters
such as routers from consumers like your own handlers or other middleware like binding frameworks.
This supports interoperability so that you can plug and play which middleware you like as long as they support Dart Path.
In a nutshell, Shelf Path encapsulates the storage of path parameters in the Shelf Request context property. It exposes two sets of functions:
getPathParameters
, getPathParameter
setPathParameters
, setPathParameter
, addPathParameter
Say we have an end point that serves up queries on a nomintated bank account and supports filtering by a minimum amount. The requests look like
GET /banking/account/123456/deposit?minAmount=20
One way to represent this is using the powerful Uri Template standard which is supported by the very useful Dart uri package. It supports both segment parameters and query parameters.
For example
/banking/account/{accountId}/deposit{?minAmount}
which has two path variables:
accountId
minAmount
Shelf Middleware such as routers can match the request path against this template and a map like
{
'accountId': '123456',
'minAmount': '20'
}
These path parameters can now be added to the context using the Shelf Path function addPathParameters
var pathParams = {
'accountId': '123456',
'minAmount': '20'
};
addPathParameters(pathParams);
An end user can now write a handler and extract the path parameters using getPathParameter
depositSearchHandler(request) {
var accountId = getPathParameter(request, 'accountId');
var minAmount = getPathParameter(request, 'minAmount');
return new Response.ok("Querying deposits for account $accountId for amounts >= $minAmount");
}
Add this to your package's pubspec.yaml file:
dependencies:
shelf_path: ^0.1.8
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:shelf_path/shelf_path.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.1.8 | Apr 10, 2016 |
|
|
0.1.7 | Aug 12, 2015 |
|
|
0.1.6 | Jun 25, 2015 |
|
|
0.1.5 | Jun 25, 2015 |
|
|
0.1.4 | Jun 25, 2015 |
|
|
0.1.3 | Jun 23, 2015 |
|
|
0.1.2 | Mar 20, 2015 |
|
|
0.1.1+1 | Aug 17, 2014 |
|
|
0.1.1 | Jul 19, 2014 |
|
|
0.1.0 | Jul 12, 2014 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
0
|
Health:
Code health derived from static analysis.
[more]
|
--
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
--
|
Overall:
Weighted score of the above.
[more]
|
0
|
The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.
Support Dart 2 in pubspec.yaml
.
The SDK constraint in pubspec.yaml
doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.
Make sure dartdoc
successfully runs on your package's source files. (-10 points)
Dependencies were not resolved.