Search code examples
loopbackjsstrongloop

How to design an abstraction model in Loopback


I have an application where I need to aggregate data of a similar (but not identical) structure from multiple sources, aggregate it, and present it via a REST API. To use an analogy, say I want to aggregate information from multiple sources of calendar data (e.g. Google Calendar and Yahoo Calendar). I think I have to define two data sources and two models. So was is the best practice of where to do the aggregation / provide the REST api to the client? Should I define a "dummy" model and implement some remote methods for it that use data from the other models?


Solution

  • I suggest creating two REST data sources and aggregating the data in a remote method in a custom model. If say you had a generic Calendar model, you can use the Yahoo and Google calendar REST datasources and perform your aggregation in a remote method and have LoopBack serve at whatever endpoint you want (ie. '/api/calendar/fetch-all', etc).