N
Nuxt18h ago
o.m

Why doesnt nuxt support http delete method for $fetch ?

I have this code but it causes syntax error
await $fetch("/api/template/user/1", {method: "DELETE"});
await $fetch("/api/template/user/1", {method: "DELETE"});
3 Replies
kapa.ai
kapa.ai18h ago
Hi @o.m. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I apologize, but there seems to be a misunderstanding in your question. Nuxt does support the HTTP DELETE method for $fetch. The code you provided should work correctly and does not cause a syntax error by itself. According to the Nuxt documentation on $fetch (https://nuxt.com/docs/api/utils/dollarfetch), $fetch supports all HTTP methods, including DELETE. Here's an example from the documentation that shows a POST request, but the same structure applies for DELETE:
async function addTodo() {
const todo = await $fetch('/api/todos', {
method: 'POST',
body: {
// My todo data
}
})
}
async function addTodo() {
const todo = await $fetch('/api/todos', {
method: 'POST',
body: {
// My todo data
}
})
}
Your code for a DELETE request looks correct:
await $fetch("/api/template/user/1", {method: "DELETE"});
await $fetch("/api/template/user/1", {method: "DELETE"});
If you're experiencing a syntax error, it's likely due to something else in your code or environment, not because of Nuxt's lack of support for the DELETE method. If you're still encountering issues, you might want to: 1. Check the context where this code is being used. Make sure it's within an async function or properly handled with .then(). 2. Verify that your Nuxt version is up to date. 3. Check for any other syntax errors in the surrounding code. If the problem persists, you may want to provide more context about the error you're seeing and where exactly in your code this is happening. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai18h ago
<@674984670156423171> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
o.m
o.mOP18h ago
Does anyone have a clue with this?
No description
Want results from more Discord servers?
Add your server