Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.04 KB

no-invalid-fetch-options.md

File metadata and controls

44 lines (31 loc) · 1.04 KB

Disallow invalid options in fetch() and new Request()

💼 This rule is enabled in the ✅ recommended config.

fetch() throws a TypeError when the method is GET or HEAD and a body is provided.

Fail

const response = await fetch('/', {body: 'foo=bar'});
const request = new Request('/', {body: 'foo=bar'});
const response = await fetch('/', {method: 'GET', body: 'foo=bar'});
const request = new Request('/', {method: 'GET', body: 'foo=bar'});

Pass

const response = await fetch('/', {method: 'HEAD'});
const request = new Request('/', {method: 'HEAD'});
const response = await fetch('/', {method: 'POST', body: 'foo=bar'});
const request = new Request('/', {method: 'POST', body: 'foo=bar'});