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?