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

PutRequest

The PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload.

PUT request should be used when you want to create a new resource at a known resourceUri (e.g. /books/0-688-00230-7) or replace an existing resource at such resourceUri.

PUT request is idempotent: calling it once or several times successively has the same effect (that is no side effect).

Extends:

Question<Promise<AxiosRequestConfig>>HTTPRequest → PutRequest

Examples:

Create a new resource at a known location
 import { Actor } from '@serenity-js/core';
 import { CallAnApi, LastResponse, PutRequest, 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(PutRequest.to('/books/0-688-00230-7').with({
         isbn: '0-688-00230-7',
         title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
         author: 'Robert M. Pirsig',
     })),
     Ensure.that(LastResponse.status(), equals(201)),
 );

Tests:

Static Method Summary

Static Public Methods
public static

to(resourceUri: Answerable<string>): PutRequest

Configures the object with a destination URI.

Method Summary

Public Methods
public

using(config: Answerable<AxiosRequestConfig>): PutRequest

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

public

with(data: Answerable<any>): PutRequest

Configures the object with a request body.

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

PutRequest

Public Methods

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

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

Params:

NameTypeAttributeDescription
config Answerable<AxiosRequestConfig>

Axios request configuration overrides

Returns:

PutRequest

public with(data: Answerable<any>): PutRequest source

Configures the object with a request body.

Params:

NameTypeAttributeDescription
data Answerable<any>

Data to be sent to the resourceUri

Returns:

PutRequest