A web service may need to store client-specific information between different requests or sessions. This data may include a username, goods added to the shopping cart, customization, and so on. The server puts this information to cookies and sends them to a client.
A cookie is a name-value pair represented in plain text. When the client sends requests to the web service again, it includes the cookies to the request, so the web service gets the required data.
How Does It Work
When a web service needs to store information for later use, it adds the Set-Cookie
header to the response. The value of the header contains the name and value of a cookie.
Optionally, the Set-Cookie
header may specify directives – additional parameters that control lifetime, visibility for server resources and so on. To learn more about possible directives, see the documentation on the MDN Web Docs website. For example, the following header specifies the cookie visible for the /store resource and its child resources:
Once a client receives this header in one of the responses, it should save the cookie. After this, the subsequent client requests to the same server will contain the Cookie
header that specifies stored cookies. The client stores cookies until they expire or the HTTP session is closed. The sent cookies may look like this:
Use Cookies in Functional Tests
Store Received Cookies
By default, ReadyAPI does not store any cookies. To change this behavior, enable the Session test case option:
It forces ReadyAPI to store received cookies and include them to the subsequent requests to the server:
Add Cookies Manually
Use Cookies in Performance Tests
When ReadyAPI runs load tests, it executes underlying test cases. If the Session test case option is enabled for them, ReadyAPI stores cookies received during the sessions. In this case, virtual users have separate HTTP sessions, so cookies received by one of them will not affect others.
Using Cookies in Virtual Services
Mock services simulate web services, so they can send cookies to clients. For this, use the Set-Cookie
header with the name and value of the cookie:
You can specify as many Set-Cookie
headers as you need.
Each cookie can contain directives that control a cookie’s lifetime, visibility for server resources, and so on. For example, the following header specifies a cookie that expires in 30 seconds:
To learn more about directives, see the documentation on the MDN Web Docs website.
See Also
Testing APIs
Test Case Editor
Request Editor Interface
Creating Responses