Skip to content

Instantly share code, notes, and snippets.

@ThomasLocke
Created October 12, 2014 15:10
Show Gist options
  • Save ThomasLocke/a79096f4a369d8c310c6 to your computer and use it in GitHub Desktop.
Save ThomasLocke/a79096f4a369d8c310c6 to your computer and use it in GitHub Desktop.
shelf.middleware.handlers.dart
library shelfmiddleware.handlers;
import 'headers.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf_path/shelf_path.dart';
shelf.Response app(shelf.Request request) {
final String myToken = getPathParameter(request, 'token');
final String html = '''
<h1>/app</h1>
<p>We welcome you here with your ${myToken} token!</p>
<p>why don't you go visit the <a href="/foo?token=${myToken}">/foo</a> resource?</p>
''';
return new shelf.Response.ok(html, headers: textHtmlHeader);
}
shelf.Response foo(shelf.Request request) {
final String myToken = getPathParameter(request, 'token');
final String html = '''
<h1>/foo</h1>
<p>You've arrived at /foo with the ${myToken} token</p>
<p>Go <a href="/app?token=${myToken}">back</a></p>
''';
return new shelf.Response.ok(html, headers: textHtmlHeader);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment