@serenity-js/rest
v3.37.0
Published
Serenity/JS Screenplay Pattern library for interacting with REST and other HTTP-based services, supporting comprehensive API testing and blended testing scenarios
Maintainers
Readme
Serenity/JS REST
@serenity-js/rest enables actors to perform HTTP requests and validate responses in Screenplay tests.
Features
- Integrates Serenity/JS with Axios providing standardised Screenplay REST API
- Compatible with all the Serenity/JS modules and supported test runners
Installation
npm install --save-dev @serenity-js/core @serenity-js/rest @serenity-js/assertions axiosSee the Serenity/JS Installation Guide.
Quick Start
import { actorCalled } from '@serenity-js/core'
import { CallAnApi, DeleteRequest, GetRequest, LastResponse, PostRequest, Send } from '@serenity-js/rest'
import { Ensure, equals, startsWith } from '@serenity-js/assertions'
const actor = actorCalled('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'))
await actor.attemptsTo(
// no users present in the system
Send.a(GetRequest.to('/users')),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body(), equals([])),
// create a new test user account
Send.a(PostRequest.to('/users').with({
login: 'tester',
password: 'P@ssword1',
}),
Ensure.that(LastResponse.status(), equals(201)),
Ensure.that(LastResponse.header('Location'), startsWith('/users')),
// delete the test user account
Send.a(DeleteRequest.to(LastResponse.header('Location'))),
Ensure.that(LastResponse.status(), equals(200)),
)Explore practical examples and in-depth explanations in the Serenity/JS Handbook.
Documentation
- API Reference
- Screenplay Pattern Guide
- Serenity/JS Project Templates
- Tutorial: First Web Scenario
- Tutorial: First API Scenario
Contributing
Contributions of all kinds are welcome! Get started with the Contributing Guide.
Community
- Community Chat
- Discussions Forum
- Visit the 💡How to... ? section for answers to common questions
If you enjoy using Serenity/JS, make sure to star ⭐️ Serenity/JS on GitHub to help others discover the framework!
License
The Serenity/JS code base is licensed under the Apache-2.0 license, while its documentation and the Serenity/JS Handbook are licensed under the Creative Commons BY-NC-SA 4.0 International.
See the Serenity/JS License.
Support
Support ongoing development through GitHub Sponsors. Sponsors gain access to Serenity/JS Playbooks and priority help in the Discussions Forum.
For corporate sponsorship or commercial support, please contact Jan Molak.
