繁体   English   中英

使用 Mongoose 在另一个 API - Node.js 中调用 API

[英]Call an API inside another API - Node.js with Mongoose

我有一个 API 与公司的某些路线,例如:

// Company
routes.get("/company", companyController.getCompanies); // Obter todas as empresas
routes.post("/company", companyController.saveCompany); // Registar uma empresa

一家公司 class 有这个:

const Company = mongoose.Schema(
  {
    name : { type: String, required: true },
    description : { type: String, required: true },
    location : { type: String, required: true },
    numberOfEmployees: { type: Number, required: false },
    subjectAreas: { type: String, required: true },
    username : { type: String, required: true },
    email : { type: String, required: true },
    password : { type: String, required: true }
  }
)

但现在我想知道公司所在地的天气。 我需要用我的 API 创建另一条路线吗? 我可以从哪里开始? 我正在考虑使用 Accuweather API 但不知道如何开始。 有什么帮助吗?

我正在使用 node.js、javascript

很简单,您可以在当前 controller 中调用 Accuweather API 并将响应保存在数据库中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM