ServiceStack - 具有多个 DTO 层的路由

标签 servicestack routes

我有 RequestDTO,该类中有另一个 DTO,它看起来像这样:

[Route("/TheDtoRequest", "GET")]
[Route("/TheDtoRequest/{do_something_here_to_fill_foobar}", "GET")]
public class TheDtoRequest
{
    public string Foo { get; set; }
    public int Bar { get; set; }
    public FooBar Foobar { get; set; }
}


public class FooBar
{
    public string AnotherFoo {get; set;}
    public int AnotherBar {get; set;}
}

如何使用 AnotherFoo 参数进行请求?

最佳答案

您可以使用 JSV 格式将 GET 请求中的 FooBar 参数填充到 /TheDtoRequest。您可以了解JSV format here 。 JSV 格式(即类似 JSON 的分隔值)是一种受 JSON 启发的格式,它使用 CSV 样式的转义来实现最少的开销和最佳的性能。

/TheDtoRequest?Foo=hello&Bar=1&FooBar={AnotherFoo:HelloWorld,AnotherBar:123}

因此,对 /TheDtoRequest 路由的查询会导致类被填充。但您也可以在路由中使用 JSV。因此给出这条路线:

/TheDtoRequest/{Foobar}

查询将产生相同的填充对象:

/TheDtoRequest/{AnotherFoo:HelloWorld,AnotherBar:123}?Foo=hello&Bar=1

或者这条路线:

/TheDtoRequest/{Foo}/{Bar}/{Foobar}

/TheDtoRequest/hello/1/{AnotherFoo:HelloWorld,AnotherBar:123}

有一个很好的例子 more complex object represented as JSV here .

希望这有帮助。

关于ServiceStack - 具有多个 DTO 层的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22244343/

相关文章:

rest - 具有ravendb id的ServiceStack路由

c# - 在Redis中存储带有DateTime键的对象

ruby-on-rails - 路由错误 : uninitialized constant Sessions

java - Mapbox(安卓)不显示方向

algorithm - Dijkstra算法计算N条最短路径

php - 如何访问 Laravel API 路由?

c# - 如何在 ServiceStack 中实现 JSONP 格式化程序

web-services - ServiceStack Web服务安全性

c# - 客户端断开连接的 ServiceStack 事件

cakephp - 在 CakePHP 中按主机名路由