【问题标题】:ServiceStack JsonServiceClient URLsServiceStack JsonServiceClient URL
【发布时间】:2021-12-03 04:40:35
【问题描述】:

我正在评估 ServiceStack JsonServiceClient 并且请求使用通用 /json/reply 端点:

https://techstacks.io/json/reply/GetTechnology?slug=ServiceStack

是否可以使用服务中声明的端点(例如:[Route("/hello")])?

【问题讨论】:

    标签: servicestack


    【解决方案1】:

    .NET (C#,F#,VB.NET) JsonServiceClient 确实使用用户定义的路由,因为它们能够访问 .NET 元数据属性,而其他语言则不能,因为它们无法访问相同的运行时元数据因此它们通常在 cmets 中发出用于文档目的,并使用 ServiceStack 的 pre-defined routes,默认情况下在所有 ServiceStack 服务上启用,这允许更简单的通用实现,可以调用任何 API。

    所有语言的所有 JsonServiceClient 还提供 API 方法,这些方法接受可用于call APIs using your user-defined routes 的字符串路径,例如:

    client.get<GetTechnologyResponse>("/technology/ServiceStack")
    
    client.get<GetTechnologyResponse>("https://techstacks.io/technology/Redis")
    
    // https://techstacks.io/technology?Slug=ServiceStack
    client.get<GetTechnologyResponse>("/technology", { Slug: "ServiceStack" }) 
    

    以及 POST 请求 DTO 到自定义 URL:

    client.postToUrl("/custom-path", request, { Slug: "ServiceStack" });
    
    client.putToUrl("http://example.org/custom-path", request);
    

    JS 库还包含some additional APIs,它可以帮助为用户定义的路由生成填充的查询字符串,例如:

    combinePaths("path","to","..","join")   //= path/join
    createPath("path/{foo}", {foo:1,bar:2}) //= path/1
    
    createUrl("http://host/path/{foo}",{foo:1,bar:2}) //= http://host/path/1?bar=2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 2022-06-28
      • 2016-12-29
      • 2017-11-22
      • 2015-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多