redstone-dart / redstone

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

List support for @app.QueryParam #53

Closed nistvan86 closed 8 years ago

nistvan86 commented 9 years ago

I've just tried this, and it doesn't work:

@app.Route("/id-test")
test(@app.QueryParam("id") List<String> ids) {
 return ids.join("+");
}

I'm calling it like:

/id-test?id=bla&id=32&id=124

Please support this argument variant.

iamsalnikov commented 9 years ago

Now I create test method:

@app.Route("/id-test")
test(@app.QueryParam("id") ids) {
 return ids.join("+");
}

Then I implement query:

/id-test?id=%5B123,2,3%5d

And result: List<int>

nistvan86 commented 9 years ago

I didn't came up with this syntax on my own. Here are some examples for this argument usage from other libraries. I think this should be implemented the same way in Redstone.dart.

JAX-RS

    @GET
    @Path("/query")
    public Response getUsers(
        @QueryParam("from") int from,
        @QueryParam("to") int to,
        @QueryParam("orderBy") List<String> orderBy) {

        return Response
           .status(200)
           .entity("getUsers is called, from : " + from + ", to : " + to
            + ", orderBy" + orderBy.toString()).build();

    }

URI Pattern : users/query?from=100&to=200&orderBy=age&orderBy=name

Spring MVC

public String method(@RequestParam(value="phone") String[] phoneArray){
    ....
}

URI Pattern: phone=val1&phone=val2&phone=val3

luizmineo commented 9 years ago

Thanks for reporting this!

Currently, Redstone relies on the Uri class (from the Dart SDK), to parse the query string, and unfortunately, this class only supports one value per parameter. There is a issue concerning this limitation, but it seems it won't be solved in the near future.

However, I'll do some research to see if we can work around this issue somehow.

digitalfiz commented 9 years ago

I'd be very interested in this functionality too. :thumbsup:

luizmineo commented 9 years ago

Sorry for taking so long to reply. I've implemented this feature on v0.6 (which I hope to publish on github soon). Although, this feature requires a breaking change, since the request object must provide the query parameters as a Map<String, List<String>>, instead of Map<String, String>, so I won't implement it in the current (v0.5) stable branch.

nistvan86 commented 9 years ago

Thank you! :) Waiting for v0.6 then.

luizmineo commented 9 years ago

The first alpha release of Redstone v0.6 is available for test: https://github.com/luizmineo/redstone.dart/tree/v0.6

Pacane commented 8 years ago

This doesn't seem to work properly.