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. In an afterAspectsLoad method, you can get a reference to a HyperBuilder, configure it as you would for a request, and then call the registerAs method passing in your desired WireBox alias.
// config/WireBox.cfc
component {
// ...
function afterApsectsLoad() {
injector.getInstance( "HyperBuilder@hyper" )
.setBaseUrl( "https://swapi.dev/api" )
.asJson()
.registerAs( "StarWarsClient" );
}
}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 alternatively create the clients by passing in the desired defaults to the initWith method of a WireBox mapping. These arguments must match the HyperRequest property names.
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.
HyperRequest property names
If you need per-request or per-response manipulation of defaults, use the requestCallbacks and responseCallbacks hooks.

