简体   繁体   中英

Call an API inside another API - Node.js with Mongoose

I have an API with certain routes for a company, example:

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

And a company class has this:

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 }
  }
)

But now I want to know the weather in the company location. Do I need to create another route with my API? Where can I start? I'm thinking about using Accuweather API but have no idea how to start. Any help?

I'm using node.js, javascript

Simple you can call Accuweather API inside your current controller and save the response in DB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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