import {HeadRequest} from '@serenity-js/rest/lib/model'
public class | source

HeadRequest

The HTTP HEAD method requests the headers that are returned if the specified resource would be requested with an HTTP GET method. Such a request can be done before deciding to download a large resource to save bandwidth, for example.

Extends:

Question<Promise<AxiosRequestConfig>>HTTPRequest → HeadRequest

Examples:

File download test
 import { Actor } from '@serenity-js/core';
 import { CallAnApi, HeadRequest, LastResponse, Send } from '@serenity-js/rest'
 import { Ensure, equals } from '@serenity-js/assertions';

 const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));

 actor.attemptsTo(
     Send.a(HeadRequest.to('/downloads/my-test-document.pdf')),
     Ensure.that(LastResponse.status(), equals(200)),
     Ensure.that(LastResponse.header('Content-Length'), equals(256)),    // assuming we know the size of the document
 );

Tests:

Static Method Summary

Static Public Methods
public static

to(resourceUri: Answerable<string>): HeadRequest

Configures the object with a destination URI.

Method Summary

Public Methods
public

using(config: Answerable<AxiosRequestConfig>): HeadRequest

Overrides the default Axios request configuration provided when CallAnApi Ability was instantiated.

Inherited Summary

From class HTTPRequest
public

subject: string

public

answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<AxiosRequestConfig>

Resolves the Question in the context of a given Actor

Static Public Methods

public static to(resourceUri: Answerable<string>): HeadRequest source

Configures the object with a destination URI.

When the resourceUri is not a fully qualified URL but a path, such as /products/2, it gets concatenated with the URL provided to the Axios instance when the CallAnApi Ability was instantiated.

Params:

NameTypeAttributeDescription
resourceUri Answerable<string>

The URI where the Actor should send the HTTPRequest.

Returns:

HeadRequest

Public Methods

public using(config: Answerable<AxiosRequestConfig>): HeadRequest source

Overrides the default Axios request configuration provided when CallAnApi Ability was instantiated.

Params:

NameTypeAttributeDescription
config Answerable<AxiosRequestConfig>

Axios request configuration overrides

Returns:

HeadRequest