In OpenRasta is it possible to Pattern match multiple key/value pairs?

Posted by Scott Littlewood on Stack Overflow See other posts from Stack Overflow or by Scott Littlewood
Published on 2010-05-20T17:19:25Z Indexed on 2010/05/20 17:20 UTC
Read the original article Hit count: 344

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 syntax 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; }
}

© Stack Overflow or respective owner

Related posts about openrasta

Related posts about .NET