【问题标题】:How to convert curl request to JS [closed]如何将 curl 请求转换为 JS [关闭]
【发布时间】:2019-05-20 05:07:25
【问题描述】:

我从来没有使用过 curl 命令,而且我有一些任务需要处理一行 API 请求。 谁能帮我把它转换成jquery? 上周创建的热门回购请求

curl -G https://api.github.com/search/repositories --data-urlencode ";q=created:>;`date -v-1w '+%Y-%m-%d'`"; --data-urlencode ";sort=stars"; --data-urlencode ";order=desc"; -H ";Accept: application/json";

【问题讨论】:

标签: javascript jquery curl


【解决方案1】:

您可以使用此函数创建 JSON 请求所需的 URI:

const listReposURI = date => {
  const baseURI = "https://api.github.com/search/repositories";
  const dateStr = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;

  return `${baseURI}?q=created=${dateStr}&sort=stars&order=desc`
};

//

const now = new Date();
const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7);

console.log(listReposURI(lastWeek))

【讨论】:

    猜你喜欢
    • 2021-07-20
    • 1970-01-01
    • 2020-02-26
    • 2019-06-28
    • 1970-01-01
    • 2018-01-30
    • 2023-02-14
    • 2020-01-26
    • 2019-08-17
    相关资源
    最近更新 更多