Skip to content

Pass cookies with Fetch API call

JavaScripts fetch() API doesn’t pass cookies by default, but if you are working with sessions, for example, you need to pass the cookies with the API call. You can do that by including the option credentials: "include":

fetch('/api/posts', { credentials: "include" }, "GET")).then(function(resp){
    // Handle the repsonse
    // Handle errors


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.