CRUD with external REST service as Model

86 views
Skip to first unread message

David Garza

unread,
May 17, 2015, 4:00:49 PM5/17/15
to loopb...@googlegroups.com, Jon Carlson
Hello,

A couple quick questions:

1. I would like to use an external REST API service (e.g. AgileCRM). With their service, I would like to use the REST Connector within a model that allows me to CRUD AgileCRM's API. Is this possible? If so, what model should be the base (e.g. PersistedModel, Model, etc)?

2. I would like to merge data from AgileCRM and a PersistedModel (e.g. MySQL). Should I do this via relationships OR inheritance? If inheritance, which should be the parent model? It would be ideal to use all data from AgileCRM (represented as a model in LB, if possible) and add information from a local MySQL database.

3. Have you any thoughts on wrapping an API service (e.g. AgileCRM) as a connector type (e.g. REST Connector for AgileCRM, based on REST Connector)? AgileCRM has many features but their CRUD methods operate slightly different from how LB interacts with data sources.

Thanks so much for a great application and the amazing community!

With Regards,

David Garza

Raymond Feng

unread,
May 18, 2015, 6:16:40 PM5/18/15
to loopb...@googlegroups.com, Jon Carlson
1. You should use Model as the base. The PersistedModel is mostly for DB backed models.

2. We don’t support a model to be backed by more than one data sources yet. At the moment, you can create a model attached to MySQL and add custom remote methods to invoke external REST APIs via a model backed by the REST connector.

3. Sure. See - http://docs.strongloop.com/display/LB/Building+a+connector+for+a+relational+database

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.

David Garza

unread,
May 26, 2015, 8:54:45 PM5/26/15
to loopb...@googlegroups.com, Jon Carlson
Hello Raymond,

Thank you for your help! In using Model as the base, it does not appear that the CRUD methods are exposed via the API. Is this the appropriate behaviour? 

model-config.josn:

"contacts": {
    "dataSource": "agilecrm",
    "public": true
  },

Here is the JSON for my contacts model that represents the data coming back from AgileCRM. Under the relationships property I am attempting to attach additional information to the contact from the local database. Is this possible? If so, how? Thanks again!

{
  "name": "contacts",
  "plural": "contacts",
  "base": "Model",
  "properties": {
    "type": {
      "type": "string"
    },
    "tags": {
      "type": [
        "string"
      ]
    },
    "lead_score": {
      "type": "number"
    },
    "contact_company_id": {
      "type": "number"
    },
    "star_value": {
      "type": "number"
    },
    "properties": {
      "type": [
        "object"
      ]
    },
    "campaignStatus": {
      "type": [
        "object"
      ]
    },
    "unsubscribeStatus": {
      "type": [
        "object"
      ]
    },
    "emailBounceStatus": {
      "type": [
        "object"
      ]
    }
  },
  "validations": [],
  "relations": {
    "timezone": {
      "type": "embedsOne",
      "model": "timezone",
      "property": "timezone",
      "options": {
        "validate": false,
        "forceId": false
      }
    }
  },
  "acls": [],
  "methods": []
}


--
You received this message because you are subscribed to a topic in the Google Groups "LoopbackJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/loopbackjs/_bAkxyBduDM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to loopbackjs+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages