如何为嵌套REST API构建查询url参数?

问题描述 投票:0回答:2

我有以下用于搜索的REST API(json对象),我应该在URL中构建一个POST请求,以下REST API的url参数是什么?仅仅因为它是嵌套的我不知道如何构建包含问号或等号的url。

http://localhost:63020/api/search ....?

 {
    "offset": 0,
    "batchsize": 10,
    "search": {
          "scope": [2,3,32],
          "type": "basic",
          "text": {
               "value": "test*",
               "fields": [
                     "subject", "body"
                ]
          },
           "age": {
                "unit": "d",
                "amount": 365
         },
         "hasattachments": false,
        },
      "facet": "messagehits",
  }
javascript json rest api
2个回答
0
投票

因为你想使用Post请求不需要修改你的URL(https://www.w3schools.com/tags/ref_httpmethods.asp),只需将其作为文档正文传递,并处理它的服务器端。


0
投票

好吧我在Angular 4中弄清楚我正在使用HTTP客户端模块,我做了什么我只是将整个对象作为参数传递回来,我得到了一个简单的响应,简单,请参阅以下代码:

sampleSearch(){
    this.http.post('/api/search/', {
        "offset": 0,
        "batchsize": 10,
        "search": {
               "scope": [2,3,32],
               "type": "basic",
               "text": {
                      "value": "test*",
                      "fields": [
                             "subject", "body"
                      ]
               },
               "age": {
                      "unit": "d",
                      "amount": 365
               },
               "hasattachments": false,
        },
        "facet": "messagehits",
    }
     ).map(data => data).subscribe(
        res => {
          console.log(res);
        },
        err => {
          console.log("Error occured");
        }
    );

}
© www.soinside.com 2019 - 2024. All rights reserved.