Skip to content

Commit c102c15

Browse files
committed
feat(HyperRequest): Add head and options shortcut methods
1 parent 16dab5e commit c102c15

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,42 @@ Execute a DELETE request asynchronously. Returns a ColdBox Future that returns a
181181
| url | string | false | null | An optional URL to set for the request. |
182182
| body | struct | false | null | An optional body to set for the request. |
183183

184+
##### `head`
185+
186+
Execute a HEAD request.
187+
188+
| Name | Type | Required | Default | Description |
189+
| ----------- | ------ | -------- | ------- | -------------------------------------------------------------- |
190+
| url | string | false | null | An optional URL to set for the request. |
191+
| queryParams | struct | false | null | An optional struct of query parameters to set for the request. |
192+
193+
##### `headAsync`
194+
195+
Execute a HEAD request asynchronously. Returns a ColdBox Future that returns a HyperResponse.
196+
197+
| Name | Type | Required | Default | Description |
198+
| ----------- | ------ | -------- | ------- | -------------------------------------------------------------- |
199+
| url | string | false | null | An optional URL to set for the request. |
200+
| queryParams | struct | false | null | An optional struct of query parameters to set for the request. |
201+
202+
##### `options`
203+
204+
Execute an OPTIONS request.
205+
206+
| Name | Type | Required | Default | Description |
207+
| ----------- | ------ | -------- | ------- | -------------------------------------------------------------- |
208+
| url | string | false | null | An optional URL to set for the request. |
209+
| queryParams | struct | false | null | An optional struct of query parameters to set for the request. |
210+
211+
##### `optionsAsync`
212+
213+
Execute an OPTIONS request asynchronously. Returns a ColdBox Future that returns a HyperResponse.
214+
215+
| Name | Type | Required | Default | Description |
216+
| ----------- | ------ | -------- | ------- | -------------------------------------------------------------- |
217+
| url | string | false | null | An optional URL to set for the request. |
218+
| queryParams | struct | false | null | An optional struct of query parameters to set for the request. |
219+
184220
##### `send`
185221

186222
Send the HTTP request and return a HyperResponse.

models/HyperRequest.cfc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,86 @@ component accessors="true" {
383383
return sendAsync();
384384
}
385385

386+
/**
387+
* Execute a HEAD request.
388+
*
389+
* @url An optional url to set for the request.
390+
* @queryParams An optional struct of query parameters to set for the request.
391+
*
392+
* @returns A HyperResponse instance for the request.
393+
*/
394+
function head( url, queryParams ) {
395+
if ( !isNull( arguments.url ) ) {
396+
setUrl( arguments.url );
397+
}
398+
if ( !isNull( arguments.queryParams ) ) {
399+
setQueryParams( [] );
400+
withQueryParams( arguments.queryParams );
401+
}
402+
setMethod( "HEAD" );
403+
return send();
404+
}
405+
406+
/**
407+
* Execute a HEAD request asynchronously.
408+
*
409+
* @url An optional url to set for the request.
410+
* @queryParams An optional struct of query parameters to set for the request.
411+
*
412+
* @returns A ColdBox Future instance.
413+
*/
414+
function headAsync( url, queryParams ) {
415+
if ( !isNull( arguments.url ) ) {
416+
setUrl( arguments.url );
417+
}
418+
if ( !isNull( arguments.queryParams ) ) {
419+
setQueryParams( [] );
420+
withQueryParams( arguments.queryParams );
421+
}
422+
setMethod( "HEAD" );
423+
return sendAsync();
424+
}
425+
426+
/**
427+
* Execute an OPTIONS request.
428+
*
429+
* @url An optional url to set for the request.
430+
* @queryParams An optional struct of query parameters to set for the request.
431+
*
432+
* @returns A HyperResponse instance for the request.
433+
*/
434+
function options( url, queryParams ) {
435+
if ( !isNull( arguments.url ) ) {
436+
setUrl( arguments.url );
437+
}
438+
if ( !isNull( arguments.queryParams ) ) {
439+
setQueryParams( [] );
440+
withQueryParams( arguments.queryParams );
441+
}
442+
setMethod( "OPTIONS" );
443+
return send();
444+
}
445+
446+
/**
447+
* Execute an OPTIONS request asynchronously.
448+
*
449+
* @url An optional url to set for the request.
450+
* @queryParams An optional struct of query parameters to set for the request.
451+
*
452+
* @returns A ColdBox Future instance.
453+
*/
454+
function optionsAsync( url, queryParams ) {
455+
if ( !isNull( arguments.url ) ) {
456+
setUrl( arguments.url );
457+
}
458+
if ( !isNull( arguments.queryParams ) ) {
459+
setQueryParams( [] );
460+
withQueryParams( arguments.queryParams );
461+
}
462+
setMethod( "OPTIONS" );
463+
return sendAsync();
464+
}
465+
386466
/**
387467
* Add additional query parameters to the request.
388468
* Note: This will remove any values with duplicate keys prior to adding the new struct of params.

0 commit comments

Comments
 (0)