shelf_throttle

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

shelf throttle

Shelf Throttle #

A Shelf middleware that applies global throttling to all incoming requests with a given time window.
// Server
// Handle requests with a 5 seconds window.
final handler = throttle(Duration(seconds: 5)).addHandler(handleRequest);
await serve(handler, host, port);

// Client
// Handled with no delay.
get('$baseUrl/hello');
// Wait for 3 seconds of the 5 seconds window.
await Future.delayed(Duration(seconds: 3));
// Handled after another 2 seconds.
get('$baseUrl/world');
copied to clipboard
Installation #
Add package dependency to your pubspec.yaml file:
dependencies:
shelf_throttle: ^0.5.0
copied to clipboard
Get the package:
dart pub get
copied to clipboard
Alternatively, use Dart CLI to add and get the package:
dart pub add shelf_throttle
copied to clipboard
Use it in your pipeline:
import 'package:shelf_throttle/shelf_throttle.dart';

const window = Duration(seconds: 5);
Pipeline().addMiddleware(throttle(window)).addHandler(handleRequest);
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.

Related Products

More From This Creator