【问题标题】:HTTP GET Requests for Beginners - Octoprint初学者的 HTTP GET 请求 - Octoprint
【发布时间】:2019-10-30 04:55:11
【问题描述】:

我正在使用 3D 打印和 octoprint 进行个人项目,其中我试图从 Web 界面检索值,例如完成 3D 打印的剩余时间。我做了研究,似乎我必须做一个 HTTP GET 请求。我对 octoprint 的软件进行了研究,发现他们有一个 API documentation。此外,还有一个 API 密钥可以访问我的特定 octoprint 实例。我遇到的问题是我从来没有用请求编程过任何东西。我已经完成了基本的 javascript,但没有什么太先进的。我正在寻找一个人来指导我在正确的方向上提出请求并从 Web 界面中提取值。感谢您的宝贵时间。

【问题讨论】:

标签: javascript node.js get request octoprint


【解决方案1】:

按照文档发送至retrieve your API key

从这里开始使用fetch 是必经之路。这是getting the API version 的未经测试的代码,但应该很接近:

   const response = await fetch('http://your-device-url/api/version', {
     headers: {
       'Content-Type': 'application/json',
       'X-Api-Key': 'your key goes here'
     }
   });
   const json = await response.json();
   console.log('here is the version information', json);

这里有一些链接可以了解更多关于fetch

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch https://javascript.info/fetch https://medium.com/codingthesmartway-com-blog/fetch-api-introduction-to-promised-based-data-fetching-in-plain-javascript-620e54898d8e

异步函数是一个相关主题,也是您想学习的另一件事。

https://developers.google.com/web/fundamentals/primers/async-functions

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多