Use customtag or wheels model for connection code to external api?

25 views
Skip to first unread message

Thorsten Eilers

unread,
Mar 19, 2021, 12:19:21 PM3/19/21
to CFWheels

Hi,
what's the better way to connect to an external api?
Use a customtag in the wheels lib folder or put the code in a tableless wheels model?
I will use this code only in one app, so a transfer to another app is not the case.
Thorsten

Tom King

unread,
Mar 19, 2021, 12:54:10 PM3/19/21
to CFWheels
I connect to a lot of external APIs, and I tend to try and bunch their logic up into CFCs so they're there in a format I can reuse if needed.

So I'll do something like
/miscellaneous/xero/xero.cfc

then I can do stuff like
    xero = new miscellaneous.xero.xero(
      client_id = application.settings.XERO_CLIENT_ID,
      client_secret = application.settings.XERO_CLIENT_SECRET 
    ); 
     local.token = xero.refreshToken();

wherever I need to.

It just means I can encapsulate that logic in a single place, and standardise the return / get formats etc.
Nothing stopping you doing it in a tableless model I guess, but I tend to want the flexibility of it in a standard CFC incase I need to move it outside of wheels or share the code.

T

Thorsten Eilers

unread,
Mar 20, 2021, 2:53:23 AM3/20/21
to CFWheels
Thanks Tom.
This seems to be logical.
Reply all
Reply to author
Forward
0 new messages