Dipping my toes into using Hyper. I'm trying to s...
# box-products
c
Dipping my toes into using Hyper. I'm trying to set up a preconfigured Hyper Builder for a specific web API site in my
WireBox.cfc
, per the sample in the README. That works pretty well:
Copy code
var baseURL = "https://[redacted]/LFRepositoryAPI/v1/Repositories/cccsdlf10";
map( "LaserficheAPI" )
  .to( "hyper.models.HyperBuilder" )
  .asSingleton()
  .initWith(
    baseURL = baseURL
  );
I have all of my application's configuration details stored in
ColdBox.cfc
, including the
baseURL
that I hardcoded in above. Is there a way to access the
ColdBox.cfc
settings from within
ireBox.cfc
? I tried to inject the ColdBox settings, and then reference them in the first line above like so:
Copy code
property name="LaserficheAPISettings" inject="coldbox:setting:LaserficheAPI";
...
function configure() {
var baseURL = LaserficheAPISettings.baseURL;
...
But that threw an error that LaserficheAPISettings.baseURL didn't exist.
b
@cfvonner The wirebox binder itself is not created by wirebox, and therefore not injected
This would surely tear a hole in the universe since the binder must be created first in order to create WireBox!
I believe ColdBox settings are available as properties in the binder
Though, I would change your mapping DSL a bit to defer the resolution of the setting entirely
👀 1
c
I figured this was a bit of an "Inception" issue.
b
This allows you to pass an injection DSL
Something along the lines of
Copy code
initArg( name='baseURL', dsl='coldbox:setting:LaserficheAPI' )
This DSL will be evaluated at the time the mapping is built, not at the time the mapping is declared.
c
That makes sense. OK, since my
LaserficheAPI
setting in ColdBox.cfc is a struct, and has keys like
baseURL
,
username
and
password
, would this work:
Copy code
initArg( name='baseURL', dsl='coldbox:setting:LaserficheAPI.baseURL' )
b
Um, I want to say it would work in CommandBox, but not in ColdBox, lol
But you can test it
c
Didn't throw an ugly error when I reinited. Won't know for sure until I try to use the Hyper object. That's next.
b
If that doesn't work, you may have to go back to trying to get the settings in the binder. See if
Copy code
getProperty( 'LaserficheAPI' )
returns the setting in the wirebox.cfc
c
It definitely didn't like the dot reference. I ended up changing the ColdBox.cfc to have the API URL as a separate setting on its own (as
LaserficheAPIURL
), and then the other settings in
LaserficheAPISettings
. Then in WireBox.cfc I have:
Copy code
initArg( name='baseURL', dsl='coldbox:setting:LaserficheAPIURL.baseURL')
That works just fine.
b
Cool
Did you try the property though, just to see if that works?
c
No, sorry.
I think splitting the settings actually makes more sense for this app. In the CFC that will actually be calling the API, only one method (the one getting bearer tokens) will need the settings (username and password). But almost every method will be using the Hyper instance mapped in WireBox.