6

How can i add custom global header for all my fetch requests in react application. Is there any function to provide global header for all fetch request in react.

getFoo() {
        return fetch(apiUrl + "API/foo").then(
            function(response) {
                return response.json();
            });
    }

Want to add global hear for my all fetch requests in react , i am stuck here please help me and thanks in advance.

1 Answer 1

1

In your question there is nothing React specific, since fetch is not part of react.

In another words, you can write your own function that attaches headers of your liking and invokes fetch with it. You can make that function global if you really, really wish to do so. You may even monkey patch fetch with packages like fetch-intercept, but there are not many situations that could justify doing so.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.