A cookie is a small piece of data that stores information about the user on the internet. It helps websites remember things like your favorite pages, visited links, and items in your shopping cart. Cookies are also useful for authentication they can store login information and send it to the server when you visit the website, so you don’t have to enter your password every time.
Imagine you're visiting a candy store. When you walk in, the person at the door gives you a little name tag with your name and favorite candy written on it. Every time you come back to that store, they look at your name tag and go:
"Oh! I remember you! You love chocolate!"
That little name tag is like a cookie on the internet. It's a small note that websites use to remember things about you.
When you visit a website, it gives your browser a small piece of data called a cookie. Your browser stores this cookie and sends it back to the website the next time you visit. This helps the website remember who you are and keep things like your login or preferences.
Bruno provides a powerful Cookie API that allows you to manage cookies programmatically via scripts, offering more control over operations such as get, set, and delete. You can also manage cookies manually using the Cookies UI section available in Bruno.
To use the Cookie API in scripts, you first need to create a cookie jar instance using the bru
object.
Create Cookie Jar Instance
const jar = bru.cookies.jar();
const jar = bru.cookies.jar();
Adds a new cookie to the jar. The cookie must follow the standard cookie format.
Set a single cookie for a specific domain with the setCookie method. You have to provide the domain URL and name as two arguments separated by a comma.
jar.setCookie("https://google.com", "test", "123abc");
Open the cookie UI from the bottom-right corner, and it will be available to use.
You can also set multiple cookies to a specific domain by adding more than one option to the setCookies method.
jar.setCookies("https://google.com", [
{
name: 'token',
value: 'xyz789',
path: '/',
secure: true
},
{
name: 'user',
value: 'melanie',
path: '/'
}
]);
Retrieves a cookie by its name and URL. You can also get all the cookies you have added to the jar with the getCookies method.
Get a single cookie by providing the URL and name of the cookie to the getCookie method.
const token = await jar.getCookie("https://google.com", "test");
console.log(token);
To get all cookies added in the jar instance, use the getCookies method.
const allCookies = await jar.getCookies();
console.log(allCookies);
You can delete a single cookie and also multiple cookies associated with a particular domain using the deleteCookies method.
Deletes a specific cookie by providing URL and name.
jar.deleteCookie("https://google.com",'test');
You can delete all cookies associated with the specific URL.
jar.deleteCookies("https://google.com");
You can clear all cookies from the jar using the clear method.
jar.clear();
If you prefer not to script cookie operations, you can manage them manually through the Cookies UI section in Bruno, where you can view, add, edit, or delete cookies directly.
Bruno gives you full control over cookies with scripting APIs, letting you manage them directly from your pre- and post-request scripts. With Cookie APIs, you can set, get, delete, and clear cookies — whether it's a single value or multiple at once.
Join our Discord server because your APIs deserve better collaboration.