Skip to content

fetchMethodBodies

Disallow providing a body with GET or HEAD fetch requests.

✅ This rule is included in the ts logical and logicalStrict presets.

The Fetch API throws a TypeError at runtime when the request method is GET or HEAD and a body is provided. This rule detects fetch() calls and new Request() calls that provide a body with a GET or HEAD method.

HTTP methods GET and HEAD are intended to retrieve data without sending a request body. Per the Fetch specification, providing a body with these methods is invalid and will cause the browser or runtime to throw an error.

AEconsB0responAE = awaiB0fet5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D/a1<1"sp ansty="le--0:#C792EA;--1:#8844">AE, { body<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dda1<1"sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0responAE = awaiB0fet5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D/a1<1"sp ansty="le--0:#C792EA;--1:#8844">AE, { method<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DG1<1"sp ansty="le--0:#C792EA;--1:#8844">AE, body<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dda1<1"sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0responAE = awaiB0fet5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D/a1<1"sp ansty="le--0:#C792EA;--1:#8844">AE, { method<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DHE1<1"sp ansty="le--0:#C792EA;--1:#8844">AE, body<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dda1<1"sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0requeAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0Reque5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D/a1<1"sp ansty="le--0:#C792EA;--1:#8844">AE, { body<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dda1<1"sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0requeAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0Reque5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D/a1<1"sp ansty="le--0:#C792EA;--1:#8844">AE, { method<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DG1<1"sp ansty="le--0:#C792EA;--1:#8844">AE, body<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dda1<1"sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEco61B0resp44AE = aw61B0f31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><;di vdivclass="Nameexpressive-">44AEco61B0resp44AE = aw61B0f31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#C792EA;--1:#88">44AE, { meth1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#C792EA;--1:#88">44AE, bo1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#C792EA;--1:#88">443F<53) ;divclass="Name">< })><;di vdivclass="Nameexpressive-">44AEco61B0resp44AE = aw61B0f31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#C792EA;--1:#88">44AE, { meth1<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#C792EA;--1:#88">44AE, bo1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#C792EA;--1:#88">443F<53) ;divclass="Name">< })><;di vdivclass="Nameexpressive-">44AEco61B0req44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Req31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#C792EA;--1:#88">44AE, { meth1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#C792EA;--1:#88">44AE, bo1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#C792EA;--1:#88">443F<53) ;divclass="Name">< })>

This rule is not configurable.

If your codebase uses a custom fetch wrapper or polyfill that accepts different options, this rule might produce false positives. You can disable it for files that use such wrappers.