OLD | NEW |
---|---|
(Empty) | |
1 #Shelf | |
nweiz
2014/04/01 19:13:11
This is unnecessary.
kevmoo
2014/04/01 19:24:04
Done.
| |
2 ### Web Server Middleware for Dart | |
3 | |
4 ## tl;dr | |
5 | |
6 **Shelf** makes it easy to create and compose **web servers** and **parts of web | |
7 servers**. How? | |
8 | |
9 * Expose a small set of simple types. | |
10 * Map server logic into a simple function: a single argument for the request, | |
11 the response is the return value. | |
12 * Trivially mix and match synchronous and asynchronous processing. | |
13 * Flexibliity to return a simple string or a byte stream with the same model. | |
14 | |
15 ## Example | |
16 | |
17 See `example/example_server.dart` | |
18 | |
19 ```dart | |
20 import 'package:shelf/shelf.dart' as shelf; | |
21 import 'package:shelf/shelf_io.dart' as io; | |
22 | |
23 void main() { | |
24 var handler = const shelf.Stack().addMiddleware(shelf.logRequests()) | |
25 .addHandler(_echoRequest); | |
26 | |
27 io.serve(handler, 'localhost', 8080).then((server) { | |
28 print('Serving at http://${server.address.host}:${server.port}'); | |
29 }); | |
30 } | |
31 | |
32 shelf.Response _echoRequest(shelf.Request request) { | |
33 return new shelf.Response.ok('Request for "${request.pathInfo}"'); | |
34 } | |
35 ``` | |
36 | |
37 ## Inspiration | |
38 | |
39 * [Connect](http://www.senchalabs.org/connect/) for NodeJS. | |
40 * Read [this great write-up](http://howtonode.org/connect-it) to understand | |
41 the overall philosophy of all of these models. | |
42 * [Rack](http://rack.github.io/) for Ruby. | |
43 * [WSGI](http://legacy.python.org/dev/peps/pep-3333/) for Python. | |
OLD | NEW |