ServiceStack:以“/ people?includes = A,B,C”的形式处理查询参数

时间:2013-09-09 16:30:58

标签: servicestack

假设传入的GET请求包含原始URL:

/people?includes=family,friends,enemies

从服务方面,是在我的Request对象中添加一个名为“Includes”的字符串[]属性,并解析数组中的每个项目,然后以正确的方式执行我的业务逻辑?

或者,或许,不是去一个字符串[]路线,有没有办法强烈输入这个(可能是一个Flags枚举?)所以我的客户和服务可以使这看起来更好?

1 个答案:

答案 0 :(得分:2)

查看ServiceStack.Text.EnumMemberSerializer

public enum ReturnPolicy
{
    NotSet = 0,
    [EnumMember(Value = @"90 Days w/Receipt")]
    _90DayswReceipt = 1,
    [EnumMember(Value = @"15% Restocking Fee")]
    _15RestockingFee = 2,
    [EnumMember(Value = @"Exchange Only")]
    ExchangeOnly = 3,
    [EnumMember(Value = @"As-Is")]
    AsIs = 4,
    ...
}

public class ProductInfo
{
    public string ProductName { get; set; }
    public ReturnPolicy ReturnPolicy { get; set; }
    ...
}

http://myhost/products?returnpolicy=90%20Days%20w%2FReceipt
http://myhost/products?returnpolicy=90%20DaYS%20w%2FReceIPt
http://myhost/products?returnpolicy=_90DayswReceipt
http://myhost/products?returnpolicy=1