A Visual Studio Code extension that helps you avoid a common mistake when using the fetch API: forgetting to set the "Content-Type": "application/json" header when sending JSON data in the request body.
- Automatic detection: Scans your JavaScript/TypeScript files for
fetchcalls that usebody: JSON.stringify(...)but are missing the correct Content-Type header. - Real-time feedback: Shows a yellow squiggly line under the problematic
JSON.stringifycall and a warning message. - Native integration: Uses VS Code's Problems panel and diagnostics system for seamless feedback.
// ❌ This will show a warning
fetch("/api/data", {
method: "POST",
body: JSON.stringify(data), // <- squiggly line here
});
// ✅ This won't show a warning
fetch("/api/data", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});- Activates for JavaScript, TypeScript, and their React variants.
- Monitors your code as you type or open files.
- Detects
fetchcalls with a JSON body but missing the correct Content-Type header. - Warns you with a squiggly line and a message:
Using JSON.stringify() without "Content-Type": "application/json" header.
- JavaScript (
.js) - TypeScript (
.ts) - JavaScript React (
.jsx) - TypeScript React (
.tsx)
- Visual Studio Code v1.74.0 or newer
- Install the extension from the VS Code Marketplace or your preferred method.
- Open or edit any supported file.
- Warnings will appear automatically as you type or open files—no configuration needed.
- Only works for direct
fetchcalls with object options. - May not detect all dynamic or indirect usages of
fetch. - Does not support languages other than JavaScript/TypeScript and their React variants.
- Initial release: Detects missing
Content-Type: application/jsonheader infetchcalls with JSON bodies.
Enjoy safer, more reliable API calls!