Middleware reqContent

maiah edited this page Oct 3, 2012 · 1 revision
Clone this wiki locally

reqContent

Use this middleware if you want to parse request POST content. Once used, the content will be available thru Request's dataMap field.

Sample usage

#import('package:synth/synth.dart');

main() {
  use(reqContent);

  route('GET', '/login', (req, res) {
    res.write(
        '''
        <!DOCTYPE html>
        <html>
        <body>
        <form action="/login" method="POST">
        <input type="text" name="username" placeholder="Username" /><br />
        <input type="password" name="password" placeholder="Password" /><br />
        <input type="submit" value="Login" />
        </form>
        </body>
        </html>
        '''
        );
  });

  route('POST', '/login', (req, res) {
    res.write("Hello ${req.dataMap['username']}");
  });

  start(7000);
  print('Listening on port 7000');
}

Run this program and access the server path http://localhost:7000/login and type maiah for username and 12345 for password and you will get the response below.

Hello maiah