getPathParameter method

String getPathParameter(
  1. String key
)

get value of the query parameter key in the shelf_router/params context

Implementation

String getPathParameter(String key) {
  final params =
      (context['shelf_router/params'] as Map<String, String>?) ??
      <String, String>{};
  if (!params.containsKey(key)) {
    throw StateError('''
request.getPathParameter($key) called with a request context that does not contain a value in context['shelf_router/params'][$key].
This can happen if $key was not provided to the shelf_router path params context.

Here is an example on how to provide a path parameter
```dart
// router.dart
final router = Router()
  ..put(
    '/<todoId|\\d+>',
    Pipeline()
        .addMiddleware(update_todo.middleware())
        .addHandler(update_todo.handler),
  )

//  middleware.dart
Middleware middleware() => Pipeline()
  .addMiddleware(provide<TodoIdPathParameter>(
      (request) => int.parse(request.getPathParameter('todoId'))))
  .middleware;
```
''');
  }
  return params[key]!;
}