Transforming REST APIs from multiple sources into a generic model and corresponding REST API

315 views
Skip to first unread message

Alffrey George

unread,
Aug 1, 2014, 7:06:45 AM8/1/14
to loopb...@googlegroups.com
Hi,

Use case: 
I have an existing back end eCommerce system with REST APIs exposed. I am building a standalone front end system (backbone js + handlebars js) which will use a slightly different and generic set of models and corresponding REST APIs. This is being done so that later on I would be able to swap one back end eCommerce system with another without disturbing the front end.

I understand that Loopback provides a rest connector using which I would be able to configure my existing REST APIs as a data source. Documentation also points out that models with custom logic can be built to use this data source. I was wondering if I can use this approach to transform the JSON request response from one format to the other i.e. convert the json response sent by eCommerce into the generic format expected by my front end system and vice-versa. I want to create the generic models and corresponding REST APIs using Loopback.

Is this the right approach and use of Loopback?

Regards,

Alffrey George

Raymond Feng

unread,
Aug 1, 2014, 11:58:40 AM8/1/14
to Alffrey George, loopb...@googlegroups.com
Sure. You can define REST data sources to your existing APIs, say you’ll get a few REST models, such as Model1 and Model2.

Then you can create a facade model, say Model0. You can add custom methods onto Model0, and implement them using methods from Model1 and Model2 to aggregate/transform the responses. The custom methods can then be exposed to REST as new APIs using LoopBack.

It’s a typical use case for service/data mashup with LoopBack.

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Prashant Bhadauria

unread,
Nov 18, 2014, 1:48:20 PM11/18/14
to loopb...@googlegroups.com
Hi Raymond,

Can you package the Model1 and Model2 as part of a re-usable connector? My thinking is that I was a create custom connector thats calls specific REST API and exposes Models. Now any one within the organization can create a loopback application, use the custom reusable connector and author aggregated API as needed. I have been searching for an example code but no luck.

~ Prashant

Raymond Feng

unread,
Nov 18, 2014, 1:51:48 PM11/18/14
to Prashant Bhadauria, loopb...@googlegroups.com
We’re working on ‘component architecture’ that will allow certain artifacts such as Model/Connector/Policy (middleware/hook) to be packaged into separate modules (components). 

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

Prashant Bhadauria

unread,
Nov 18, 2014, 1:59:52 PM11/18/14
to Raymond Feng, loopb...@googlegroups.com, Prashant Bhadauria
Thanks Raymond for the quick reply. Just to give you a bit of the perspective, here is what I am thinking:

1) Create a reusable component that carries standard commerce model definition and associated remote methods
2) Create a reusable connector specific to commerce package that implements the above models
3) Finally create a Loopback application that can use the above two and create channel specific API

Do you think the proposed component architecture solves this?

~ Prashant

Raymond Feng

unread,
Nov 18, 2014, 2:01:25 PM11/18/14
to Prashant Bhadauria, loopb...@googlegroups.com, Prashant Bhadauria
Yes, the component architecture will fully enable that.

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

Reply all
Reply to author
Forward
0 new messages