Seal classes in shelf_router and prepare 0.7.3 (#85)
* Updated README.md, adding links to third-party tutorial :D
* Prefer spread collections
* Add @sealed route and bumped to 0.7.3
* Cleanup README
diff --git a/pkgs/shelf_router/CHANGELOG.md b/pkgs/shelf_router/CHANGELOG.md
index 08a1d6c..f3e0569 100644
--- a/pkgs/shelf_router/CHANGELOG.md
+++ b/pkgs/shelf_router/CHANGELOG.md
@@ -1,3 +1,7 @@
+## v0.7.3
+
+ * Added `@sealed` annotation to `Router` and `Route`.
+
## v0.7.2
* Always register a `HEAD` handler whenever a `GET` handler is registered.
diff --git a/pkgs/shelf_router/README.md b/pkgs/shelf_router/README.md
index 87addb8..6738d15 100644
--- a/pkgs/shelf_router/README.md
+++ b/pkgs/shelf_router/README.md
@@ -1,12 +1,13 @@
# Web Request Router for Shelf
-[Shelf](https://pub.dartlang.org/packages/shelf) makes it easy to build web
+[Shelf][shelf] makes it easy to build web
applications in Dart by composing request handlers. This package offers a
request router for Shelf, matching request to handlers using route patterns.
**Disclaimer:** This is not an officially supported Google product.
-Also see the `shelf_router_generator` package for how to automatically generate
+Also see the [`shelf_router_generator`][shelf_router_generator] package
+for how to automatically generate
a `Route` using the `Route` annotation in this package.
## Example
@@ -31,3 +32,16 @@
See reference documentation of `Router` class for more information.
+## See also
+ * Package [`shelf`][shelf] for which this package can create routers.
+ * Package [`shelf_router_generator`][shelf_router_generator] which can generate
+ a router using source code annotations.
+ * Third-party tutorial by [creativebracket.com]:
+ * Video: [Build RESTful Web APIs with shelf_router][1]
+ * Sample: [repository for tutorial][2]
+
+[shelf]: https://pub.dev/packages/shelf
+[shelf_router_generator]: https://pub.dev/packages/shelf_router_generator
+[creativebracket.com]: https://creativebracket.com/
+[1]: https://www.youtube.com/watch?v=v7FhaV9e3yY
+[2]: https://github.com/graphicbeacon/shelf_router_api_tutorial
diff --git a/pkgs/shelf_router/lib/shelf_router.dart b/pkgs/shelf_router/lib/shelf_router.dart
index 9492dda..dcf4f7d 100644
--- a/pkgs/shelf_router/lib/shelf_router.dart
+++ b/pkgs/shelf_router/lib/shelf_router.dart
@@ -79,7 +79,7 @@
///
library shelf_router;
-import 'src/router.dart';
-import 'src/route.dart';
-export 'src/router.dart';
-export 'src/route.dart';
+import 'package:shelf_router/src/router.dart';
+import 'package:shelf_router/src/route.dart';
+export 'package:shelf_router/src/router.dart';
+export 'package:shelf_router/src/route.dart';
diff --git a/pkgs/shelf_router/lib/src/route.dart b/pkgs/shelf_router/lib/src/route.dart
index 10a8104..62da18f 100644
--- a/pkgs/shelf_router/lib/src/route.dart
+++ b/pkgs/shelf_router/lib/src/route.dart
@@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import 'router.dart';
+import 'package:meta/meta.dart' show sealed;
+import 'package:shelf_router/src/router.dart';
/// Annotation for handler methods that requests should be routed when using
/// package `shelf_router_generator`.
@@ -45,6 +46,7 @@
///
/// It is also permitted to annotate public members, the only requirement is
/// that the member has a signature accepted by [Router] as `handler`.
+@sealed
class Route {
/// HTTP verb for requests routed to the annotated method.
final String verb;
diff --git a/pkgs/shelf_router/lib/src/router.dart b/pkgs/shelf_router/lib/src/router.dart
index a6b8711..a3102cd 100644
--- a/pkgs/shelf_router/lib/src/router.dart
+++ b/pkgs/shelf_router/lib/src/router.dart
@@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import 'router_entry.dart' show RouterEntry;
+import 'package:meta/meta.dart' show sealed;
+import 'package:shelf_router/src/router_entry.dart' show RouterEntry;
import 'package:shelf/shelf.dart';
import 'package:http_methods/http_methods.dart';
@@ -84,6 +85,7 @@
/// will be attempted.
///
///
+@sealed
class Router {
final List<RouterEntry> _routes = [];
diff --git a/pkgs/shelf_router/lib/src/router_entry.dart b/pkgs/shelf_router/lib/src/router_entry.dart
index 5130f50..d2ef901 100644
--- a/pkgs/shelf_router/lib/src/router_entry.dart
+++ b/pkgs/shelf_router/lib/src/router_entry.dart
@@ -103,8 +103,10 @@
if (_handler is Handler || _params.isEmpty) {
return await _handler(request);
}
- return await Function.apply(
- _handler, [request]..addAll(_params.map((n) => params[n])));
+ return await Function.apply(_handler, [
+ request,
+ ..._params.map((n) => params[n]),
+ ]);
})(request);
}
}
diff --git a/pkgs/shelf_router/pubspec.yaml b/pkgs/shelf_router/pubspec.yaml
index 1b02b1a..c0befeb 100644
--- a/pkgs/shelf_router/pubspec.yaml
+++ b/pkgs/shelf_router/pubspec.yaml
@@ -1,5 +1,5 @@
name: shelf_router
-version: 0.7.2
+version: 0.7.3
description: |
A convinent request router for the shelf web-framework, with support for
URL-parameters, nested routers and routers generated from source annotations.
@@ -7,6 +7,7 @@
repository: https://github.com/google/dart-neats.git
issue_tracker: https://github.com/google/dart-neats/labels/pkg:shelf_router
dependencies:
+ meta: ^1.1.7
shelf: ^0.7.3
http_methods: ^1.0.0
dev_dependencies:
@@ -14,4 +15,4 @@
pedantic: ^1.4.0
http: ^0.12.0+1
environment:
- sdk: '>=2.0.0 <3.0.0'
+ sdk: '>=2.3.0 <3.0.0'