Skip to content

Commit

Permalink
Seal classes in shelf_router and prepare 0.7.3 (dart-lang#85)
Browse files Browse the repository at this point in the history
* Updated README.md, adding links to third-party tutorial :D

* Prefer spread collections

* Add @Sealed route and bumped to 0.7.3

* Cleanup README
  • Loading branch information
jonasfj authored Nov 3, 2020
1 parent 4b4f15c commit 91b695d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
4 changes: 4 additions & 0 deletions pkgs/shelf_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 16 additions & 2 deletions pkgs/shelf_router/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,3 +32,16 @@ var server = await io.serve(app.handler, 'localhost', 8080);

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
8 changes: 4 additions & 4 deletions pkgs/shelf_router/lib/shelf_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
4 changes: 3 additions & 1 deletion pkgs/shelf_router/lib/src/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -45,6 +46,7 @@ import 'router.dart';
///
/// 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;
Expand Down
4 changes: 3 additions & 1 deletion pkgs/shelf_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -84,6 +85,7 @@ final _removeBody = createMiddleware(responseHandler: (r) {
/// will be attempted.
///
///
@sealed
class Router {
final List<RouterEntry> _routes = [];

Expand Down
6 changes: 4 additions & 2 deletions pkgs/shelf_router/lib/src/router_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ class RouterEntry {
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);
}
}
5 changes: 3 additions & 2 deletions pkgs/shelf_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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.
homepage: https://github.com/google/dart-neats/tree/master/shelf_router
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:
test: ^1.5.1
pedantic: ^1.4.0
http: ^0.12.0+1
environment:
sdk: '>=2.0.0 <3.0.0'
sdk: '>=2.3.0 <3.0.0'

0 comments on commit 91b695d

Please sign in to comment.