[英]How to build a query url parameters for the nested REST API?
我具有以下用於搜索的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",
}
由於您要使用發布請求,因此無需修改URL( https://www.w3schools.com/tags/ref_httpmethods.asp ),只需將其作為文檔正文傳遞,並在服務器端進行處理即可。
好的,所以可以在Anagular 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");
}
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.