2022-03-05
|~1 min read
|177 words
When it comes to testing APIs, Postman and tools like it are quite useful!
I’ve been working on an upgrade to my blog to include authentication.
One of the consequences of this change is that once users are logged in, I send an encrypted cookie along with every request.
I wanted to be able to test my application for behaviors that would occur after logging in and use a tool like Postman instead of doing it all manually.
In order to facillitate that, I needed to be able to login with Postman and then share the cookie that the server returns between requests.
In the “Tests” tab of a request in Postman, we can set the cookie to a key that other requests will have access to:
pm.globals.set("<your key>", pm.cookies.get("<cookie name>"))
To use the cookie in a future request, you would add it on the “Headers” tab:
| Key | Value |
| ------ | -------------- |
| Cookie | {{<your key>}} |
For more on scripting with Postman, see the docs here.
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!