将JSON主体转换为REST URI(Converting a JSON body into a REST URI)

编程入门 行业动态 更新时间:2024-10-26 23:27:54
将JSON主体转换为REST URI(Converting a JSON body into a REST URI)

请问有人可以建议我如何将这个JSON主体转换为REST URI?

GET api/_search { "age":"5", "aggs" : { "uniq_gender" : { "terms" : { "field" : "Gender.keyword" } } } }

can someone please advise how can I convert this JSON body into a REST URI ?

GET api/_search { "age":"5", "aggs" : { "uniq_gender" : { "terms" : { "field" : "Gender.keyword" } } } }

最满意答案

您可以选择以下两个选项之一:

使用POST与body

POST api/_search { "age":"5", "aggs" : { "uniq_gender" : { "terms" : { "field" : "Gender.keyword" } } } }

它可能看起来像一个黑客,但它很简单,坦率地说它被广泛使用。 基本上从REST角度来看,它可以被视为资源创建( filter而不是seach可能是一个更好的词)。

将查询字符串与GET 。

就像是:

GET api/_search?age=5,field=Gender.keyword

使用查询字符串的问题是它可能是有限的。 在RFC中有一个代码用于这种情况 。 例如IE浏览器有这样的限制 - 请参阅详细信息 。

一般来说,如果没有技术问题,可能会出现可读性问题 - 很难处理1000+符号字符串。

You may proceed with one of two options:

Use POST with body

POST api/_search { "age":"5", "aggs" : { "uniq_gender" : { "terms" : { "field" : "Gender.keyword" } } } }

It may seem like a hack, but it is simple and frankly it is widely used. Basically from REST perspective it may be considered as resource creation (filter rather than seach might be a better word here).

Use query string with GET.

Something like:

GET api/_search?age=5,field=Gender.keyword

The problem with using query string is that it may be limited. In RFC there is a code for such a case. For example IE browser has such a limit - see details.

Generally speaking if there is no technical problem, readability issue may appear - it is hard to deal with 1000+ symbols string.

更多推荐

本文发布于:2023-07-26 03:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   主体   JSON   REST   body

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!