src/content/docs/linter/rules/use-static-response-methods.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/suspicious/useStaticResponseMethods`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). ## How to configure ```json title="biome.json" { "linter": { "rules": { "suspicious": { "useStaticResponseMethods": "error" } } } }## Description
Use static `Response` methods instead of `new Response()` constructor when possible.
`new Response(JSON.stringify({ value: 1 }))` can be simplified to [Response.json()](https://developer.mozilla.org/en-US/docs/Web/API/Response/json).
`new Response(null, { status: 301, headers: { location: 'https://example.com' } })` can be simplified to [Response.redirect()](https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static).
These methods are more concise and emphasize the intent of the code better,
however they are not a direct replacement when additional options such as extra headers are needed.
In case of `Response.redirect()`, the `location` header must also be a full URL, because server runtimes (Node, Deno, etc.) will throw an error for relative URLs.
## Examples
### Invalid
```js
new Response(JSON.stringify({ value: 1 }));
new Response(JSON.stringify({ value: 0 }), {
headers: {
'Content-Type': 'application/json',
}
})
new Response(null, {
headers: {
location: 'https://example.com',
},
status: 302,
})
// JSON.stringify() with a replacer function
new Response(JSON.stringify({ value: 0 }, () => {}))
new Response(null, {
headers: {
location: 'https://example.com',
'x-foo': 'extra-header',
},
status: 302,
})
new Response(null, {
headers: {
location: '/relative-url',
},
status: 302,
})