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:
Examples:
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 |
|
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> |
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:
Name | Type | Attribute | Description |
resourceUri | Answerable<string> | The URI where the Actor should send the HTTPRequest. |
Public Methods
public using(config: Answerable<AxiosRequestConfig>): PutRequest source
Params:
Name | Type | Attribute | Description |
config | Answerable<AxiosRequestConfig> | Axios request configuration overrides |
public with(data: Answerable<any>): PutRequest source
Configures the object with a request body.
Params:
Name | Type | Attribute | Description |
data | Answerable<any> | Data to be sent to the |