PUT request with tRPC

Hi everyone! First of all, I tried to find an answer to my question but I couldn’t find one. I’m trying to update an entity in my database using tRPC stack. For example, I want to edit some of my posts on my website and update their title. Everything works fine but instead of a PUT request, I see a POST request in my network tab. How can I tell to my tRPC API to send a PUT request instead of a POST request? Much appreciated!! Thank you in advance
24 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
rre
rre2y ago
what if you do a query. does it do a POST as well? out of curiosity i am quite clueless when it comes to tRPC but it seems that it's the same as in graphQL, queries and mutations. at least in graphQL you only have POST
pogadev
pogadev2y ago
Let’s assume that you have a blog and you want to create a post. For that, you’ll have a form on the client side and some inputs for the post title and post body. On submit, you send a POST request, using the useMutation hook. This POST request creates a new resource in your database. Later that day, you want to edit the post title and again, from the client side, you have a form from which you can edit the title of the post. But for that, you’ll want to send a PUT request in order to update an existing resource. (That blog post that you already have in DB) The correct way should be to send a PUT request when you create mutations for already existing entities
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
rre
rre2y ago
oh okay thanks, but yeah. it seems as in creating and updating is both POST - because they are mutations.
nexxel
nexxel2y ago
you're using trpc so you don't need to think about http methods. just do a mutation to update stuff
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
pogadev
pogadev2y ago
@flicknote the thing is that the browser is using a POST request for that 🙂
rre
rre2y ago
for mutations it does a post request
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
rre
rre2y ago
even though you're doing a mutation to update an existing entity, it will do a post in the browser this functionality seems identical to GraphQL
pogadev
pogadev2y ago
here is the code
pogadev
pogadev2y ago
yeah, but I don't like that 😆
rre
rre2y ago
why does it matter? if you ever hop on to graphql, it's the same there
pogadev
pogadev2y ago
it's not technically correct :))
Want results from more Discord servers?
Add your server