Hyper Clients
Hyper allows you to configure defaults for your requests as custom Hyper Clients. This is particularly useful for reducing boilerplate in your application.
Defaults are set on the HyperBuilder instance. The easiest way to do this is to configure it in WireBox:
// config/WireBox.cfc
component {
function configure() {
map( "StarWarsClient" )
.to( "hyper.models.HyperBuilder" )
.asSingleton()
.initWith(
baseUrl = "https://swapi.dev/api"
);
}
}Now, you can inject this pre-configured builder wherever you need in your application:
component {
property name="StarWarsClient" inject="StarWarsClient";
function findUser( id ) {
return variables.StarWarsClient.get( "/people/#id#" );
}
}You can even create multiple clients using this approach:
You can also set or change the defaults by either passing the key / value pairs in to the init method or by calling the appropriate HyperRequest method on the HyperBuilder.defaults property.
The defaults set here need to match the property names on the HyperRequest. These are:
If you need per-request or per-response manipulation of defaults, use the requestCallbacks and responseCallbacks hooks.
Last updated

