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

GetRequest

The HTTP GET method requests a representation of the specified resource. It is the most frequent type of request made by consumers of a typical HTTP API. For this reason it's important to test every known endpoint that responds to GET requests and ensure that it behaves correctly.

Since the GET method is used to retrieve data from a server, it should be implemented as safe and idempotent. This means that an identical request can be made once or several times in a row with the same effect while leaving the server in the same state.

Extends:

Question<Promise<AxiosRequestConfig>>HTTPRequest → GetRequest

Examples:

Verify response to a GET request
 import { Actor } from '@serenity-js/core';
 import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
 import { Ensure, equals } from '@serenity-js/assertions';

 interface Book {
     title: string;
     author: string;
 }

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

 actor.attemptsTo(
     Send.a(GetRequest.to('/books/0-688-00230-7')),
     Ensure.that(LastResponse.status(), equals(200)),
     Ensure.that(LastResponse.body<Book>(), equals({
         title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
         author: 'Robert M. Pirsig',
     })),
 );

Tests:

Static Method Summary

Static Public Methods
public static

to(resourceUri: Answerable<string>): GetRequest

Configures the object with a destination URI.

Method Summary

Public Methods
public

using(config: Answerable<AxiosRequestConfig>): GetRequest

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>): GetRequest 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:

GetRequest

Public Methods

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

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

Params:

NameTypeAttributeDescription
config Answerable<AxiosRequestConfig>

Axios request configuration overrides

Returns:

GetRequest