redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Fix list support for @app.QueryParam #182

Closed sestegra closed 8 years ago

sestegra commented 8 years ago

FIx #53

import 'package:redstone/redstone.dart' as app;

String typeInfo(param) {
  var info = "";
  info += param.runtimeType.toString() + ": ";
  if (param is List) {
    param.forEach((item) {
      info += "\n";
      info += "  " + item.runtimeType.toString() + ": " + item.toString();
    });
  } else {
    info += param.toString();
  }

  return info;
}

@app.Route("/id")
testId(@app.QueryParam("id") int id) {
  return typeInfo(id);
}

@app.Route("/id/int")
testIdsInt(@app.QueryParam("id") List<int> id) {
  return typeInfo(id);
}

@app.Route("/id/string")
testIdsString(@app.QueryParam("id") List<String> id) {
  return typeInfo(id);
}

main() {
  app.setupConsoleLog();
  app.start();
}
$ curl "http://127.0.0.1:8080/id?id=2&id=3"
int: 2
$ curl "http://127.0.0.1:8080/id/string?id=2&id=3"
List: 
  String: 2
  String: 3
$ curl "http://127.0.0.1:8080/id/int?id=2&id=3"
List: 
  int: 2
  int: 3
Pacane commented 8 years ago

Awesome work! Thanks a lot!