-1

Im working on js library that basically get json from a rest api, some process and return it. Well, im from Java world and i do something like that.

-- mylib.js

class ClientFetcher {
  getClientesWithProducts(clientId) {
    return fetch('api.site.com/clients/'+clientId)
   .then(....doSomething);
  }

  getClientsWithFavorites() {...}
}

class ProductFetcher {
  getActiveProducts() {
    return fetch('api.site.com/products')
    .then(...do somethind);
  }
}

Is this approach used in js world? There is some way or pattern to structure the code? Which the way that the js community usually do?

walves
  • 2,026
  • 6
  • 28
  • 46

1 Answers1

0

It depends on what js framework you use. For example, AngularJs and Angular use service to call the api in order to get those json data. Other framework may have other structure.

samAlvin
  • 1,648
  • 1
  • 11
  • 35
  • you could give some example for my study. my client had mention react but i dont find anything specific. – walves Jul 20 '17 at 10:50
  • @ulima69 for react maybe you can try to follow the explanation in this answer here: https://stackoverflow.com/a/38743378/6638533 – samAlvin Jul 20 '17 at 11:26