LogoLogo
7.3.0
7.3.0
  • Introduction
  • What's New?
  • Upgrade Guide
  • Getting Started
    • Requirements
    • Installation
  • Making Requests
    • HyperBuilder
    • HyperRequest
    • HyperResponse
  • Customizing Hyper
    • Hyper Clients
    • Custom HTTP Clients
      • CfhttpHttpClient
  • Testing
    • Faking Requests
  • ForgeBox
  • GitHub
Powered by GitBook
On this page
  1. Making Requests

HyperBuilder

PreviousInstallationNextHyperRequest

Last updated 1 year ago

A HyperBuilder is a singleton factory component that will give you a new any time you call the new method. It will also create a new any time you call a method on HyperBuilder that exists on .

HyperBuilder is the component you want to inject into your singleton components, like handlers or services. It will ensure you get a fresh instance on each invocation. This is important since reusing the same instance will likely produce unintended results.

You can inject a HyperBuilder into your application using the HyperBuilder@hyper id.

component {
    
    property name="hyper" inject="HyperBuilder@hyper";

    function index( event, rc, prc ) {
        var reqA = hyper.new();
        // reqA is a new HyperRequest instance.
        
        var reqB = hyper.setUrl( "https://swapi.dev/api/people" );
        // reqB is a new HyperRequest instance with the url set.
    }

}

If you are not using ColdBox, you can create a HyperBuilder manually:

component {

    function init() {
        variables.hyper = new hyper.models.HyperBuilder();
    }

}

Additionally, you can register HyperBuilder instances as custom HTTP Clients.

Finally, you can enable faking of requests from any HyperBuilder instance.

HyperRequest
HyperRequest
HyperRequest
HyperRequest
HyperRequest
Custom HTTP Clients
Faking Requests