question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I could have sworn we’d already talked about this at some point, but I guess not.

Is your feature request related to a problem? Please describe. Bewilderingly, the only valid <form> methods are GET and POST — in other words <form method="put"> is invalid, and will result in form.method === 'get'.

A popular workaround is to use a method override query string parameter, like so:

<form method="post" action="/todos/{id}?_method=put">
  <!-- form elements -->
</form>

(As evidence for the validity of this approach, there’s an official Express middleware for it: https://www.npmjs.com/package/method-override).

It would be nice if such a thing existed in SvelteKit as well, since we want to encourage people to build apps that work with JavaScript disabled, and that’s only really possible if you can use PUT and DELETE alongside GET and POST without having to resort to fetch.

Describe the solution you’d like Since the ?_method=put cowpath already exists, I propose that we bake it into SvelteKit, while making it configurable:

// svelte.config.cjs
module.exports = {
  kit: {
    methodOverride: {
      key: '_method',
      allowed: ['post', 'put', 'delete']
    }
  }
};

Then, when any request that comes in where query.has(override), we change the request method before passing it to handle.

How important is this feature to you? It would be possible to do in userland…

export function handle({ request, render }) {
  return render({
    ...request,
    method: request.query.get('_method') || request.method
  });
}

…but I think this is the sort of thing that belongs in the framework.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:17
  • Comments:20 (15 by maintainers)

github_iconTop GitHub Comments

14reactions
Rich-Harriscommented, Apr 17, 2021

Huh. I find it much grosser to update or delete a resource with a POST request. If HTTP methods mean anything at all, then POST /items/xyz/update means ‘create a new resource of the type /items/xyz/update’, which is incoherent.

8reactions
lukeedcommented, Apr 17, 2021

Gross 😅

Better to scaffold a server-side POST /items/:id/update endpoint imo. It can even be an alias to the same handler for PUT route.

Methods and status codes are fundamental building blocks. Paths can be reworked if need be. And there’s a much deeper cow path for shuttling everything thru POSTs if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overriding in Java - GeeksforGeeks
Method overriding is one of the way by which java achieve Run Time Polymorphism.The version of a method that is executed will be...
Read more >
Method Overriding in Java - javatpoint
If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java. In...
Read more >
Overriding and Hiding Methods (The Java™ Tutorials ...
The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and...
Read more >
Java Method Overriding - Programiz
In this tutorial, we will learn about method overriding in Java with the help of examples. If the same method defined in both...
Read more >
Overriding in Java [Methods, Uses, Examples with Output]
In Java, method overriding occurs when a subclass (child class) has the same method as the parent class. In other words, method overriding...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found