Using PUT to Create a Resource #3013
-
Is there any (straight forward) way to use PUT to create a user-named resource? In all of the htmx examples and books I have seen so far, generally POST is used, I assume because the URL for the PUT must be constructed dynamically at the last minute (in my case from the current URL and some user input.) I think I am committed to having separate hypermedia and data APIs, so it won't be a big deal to use POST for the former and PUT for the latter, but I would prefer to use PUT and would like to make sure I'm not missing anything. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, the doc indeed uses GET/POST, but that's simply because they are the most common & straightforward methods to showcase the library. It doesn't matter whether you use POST, PUT or PATCH, htmx will work the same. The only thing you need to be aware of regarding methods is that, by default, GET and DELETE will have the parameters sent as URL encoded params, while POST/PUT/PATCH will have the values in the request body. This can be configured btw (see As for your usecase, htmx indeed doesn't provide any built-in way to handle dynamic URLs. The URLs in Hope this helps |
Beta Was this translation helpful? Give feedback.
Hey, the doc indeed uses GET/POST, but that's simply because they are the most common & straightforward methods to showcase the library. It doesn't matter whether you use POST, PUT or PATCH, htmx will work the same.
The only thing you need to be aware of regarding methods is that, by default, GET and DELETE will have the parameters sent as URL encoded params, while POST/PUT/PATCH will have the values in the request body. This can be configured btw (see
htmx.config.methodsThatUseUrlParams
)As for your usecase, htmx indeed doesn't provide any built-in way to handle dynamic URLs. The URLs in
hx-post
,hx-put
etc. are parsed once when htmx processes the element, but not evaluated for each requ…