Blog

Hyper Updates - June 2023

Eric Peterson June 16, 2023

Spread the word

Eric Peterson

June 16, 2023

Spread the word


Share your thoughts

There's been lots of updates to Hyper this month, including not one but two breaking changes! (Trying to stick to semver here, even when the breaking changes seem minor.)

New Documentation Site

Perhaps the most exciting news, Hyper has a new home for documentation! We outgrew using just a README a while ago and now we finally have a brand new home for Hyper. This will make finding the documentation you need even easier.

Next to the headline new features:

asXML support

Hyper now has built-in support for dealing with XML apis using the asXML helper method.

head and options shortcut methods

Need to make head or options? Now you can do it without having to call setMethod first.

More Accurate Status Codes

Hyper now returns more accurate status codes for 502 Bad Gateway and 408 Request Timeout responses. Previously, these responses were returned as 504 Gateway Timeout responses. Hyper now normalizes the responses from the different CFML engines into a consistent response. 502 Bad Gateway is returned instead of 504 Gateway Timeout for invalid hosts. 408 Request Timeout is returned if the request takes longer than the configured timeout value.

Easier Custom Hyper Clients

It is now more straightforward to register a custom Hyper client. Inside your config/WireBox.cfc 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://api.github.com" )
           .asJson()
           .withHeaders( {
               "Authorization": coldbox.getUtil().getSystemSetting( "GITHUB_TOKEN" )
           } )
           .registerAs( "GitHubClient" );
   }

}

This is a welcome improvement as the init arguments do not exactly match the method names. Also, for defaults like requestCallbacks, responseCallbacks, or even queryParams, passing in arrays of functions or arrays or structs is not as straightforward as calling the related methods. Now, you can use the Hyper methods you are familiar with when registering your custom Hyper clients.

Faking Requests

We kind of buried the lead here, but Hyper now ships with the ability to fake requests for testing.

Here's a quick example:

hyper.fake( {
    "https://google.com/*": function( newFakeResponse, req ) {
         return newFakeResponse( 404, "Not Found" );
    }
} );

var resA = hyper.get( "https://google.com" );
expect( resA.getStatus() ).toBe( "404 Not Found" );

var resB = hyper.get( "https://does-not-exist.also-does-not-exist" );
expect( resB.getStatus() ).toBe( "200 OK" );

There's a lot to love here, so make sure to give the documentation a visit.

We hope you love these updates to Hyper! Happy HTTP'ing!

Add Your Comment

Recent Entries

Into the Box 2024: Your Gateway to the Future of Tech!

Into the Box 2024: Your Gateway to the Future of Tech!

Are you ready to advance your coding skills? The future of Modern Web Development awaits at Into the Box 2024, and we're thrilled to announce that due to high demand, we're extending our Early Bird pricing for an additional week!

Maria Jose Herrera
Maria Jose Herrera
April 26, 2024
Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024