[英]How to remove the HTTP headers from a REST api call in Javascript
Hi i am trying to isolate the part of the response in the {}.您好,我正在尝试隔离 {} 中的响应部分。 It calls from the gemini public database and i am trying to get only the part in the curly braces to save it as a string in a database.
它从双子座公共数据库调用,我试图只获取花括号中的部分以将其保存为数据库中的字符串。
const gemini = async() =>{
var burl = 'https://api.sandbox.gemini.com'
var query = '/v1/pubticker/'+'ethusd'
var url = burl + query
var smth = fetch(url)
delete smth.vary
return smth
}
export default gemini
Here is the response i get这是我得到的回应
status: 200 OK
content-length: 133
content-type: application/json
date: Mon, 08 Nov 2021 18:03:09 GMT
server: nginx
vary: Origin
{"bid":"4786.52","ask":"4787.78","volume":{"ETH":"8232.886562","USD":"38693689.50955448","timestamp":1636394400000},"last":"4786.83"}
This is what i want to isolate这就是我想要隔离的
{"ETH":"8232.886562","USD":"38693689.50955448","timestamp":1636394400000},"last":"4786.83"}
You don't need to "remove the headers".您不需要“删除标题”。 Just get the JSON response and use the data you need from that response.
只需获取 JSON 响应并使用该响应中所需的数据即可。 Your
gemini
function returns a Promise
from a fetch
call.您的
gemini
函数从fetch
调用返回一个Promise
。 You'd use that Promise
like any other fetch
call .您可以像使用任何其他
fetch
call 一样使用该Promise
。 For example:例如:
let response = await gemini();
let result = await response.json();
Then result
contains the object specified by the JSON data.然后
result
包含由 JSON 数据指定的对象。 From the description in the question it sounds like you specifically want the volume
and last
properties on that object.从问题中的描述来看,您似乎特别想要该对象的
volume
和last
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.