In OpenRasta is it possible to Pattern match multiple key/value pairs?
Is it possible in OpenRasta to have a Uri pattern that allows for an array of values of the same key to be submitted and mapped to a handler method accepting an array of the query parameters.
Example: Return all the contacts named Dave Smith from a collection.
HTTP GET /contacts?filterBy=first&filterValue=Dave&filterBy=last&filterValue=Smith
With a configuration of:
What syn开发者_运维技巧tax would be best for the Uri string pattern matching? (Suggestions welcome)
ResourceSpace.Has.ResourcesOfType<List<ContactResource>>()
.AtUri("/contacts")
.And.AtUri("/contacts?filterBy[]={filterBy}[]&filterValue[]={fv}[]") // Option 1
.And.AtUri("/contacts?filterBy={filterBy}[]&fv={fv}[]") // Option 2
Would map to a Handler method of:
public object Get(params Filter[] filters)
{
/*
create a Linq Expression based on the filters using dynamic linq
query the repository using the Linq
*/
return Query.All<Contact>().Where(c => c.First == "Dave" && c.Last == "Smith").ToResource()
}
where Filter is defined by
public class Filter
{
public string FilterBy { get; set; }
public string FilterValue { get; set; }
}
.AtUri("/contacts?filterBy={filterby}&filterValue={filterValue}")
should happily map to
Post(string[] filterby, string[] filterValues)
That should get processed the correct way, if not it's a bug.
You can also use the object syntax if you want something a bit nicer:
<input name="Filter:0.FilterBy" />
<input name="Filter:1.FilterBy" />
and have
Post(IEnuemrable<Filter> filter)
But you will probably need to use a post for this, not a get. The usual way to solve this is to do a Post-Redirect-Get to a fully built URI, which is also nicer for caching
精彩评论