https://kotlinlang.org logo
#ktor
Title
# ktor
r

rsktash

04/29/2021, 9:46 AM
Hi. Why I can’t request GET request with body?
b

Big Chungus

04/29/2021, 9:47 AM
You can via generic http request builder, but this is going against REST conventions.
All the input for get requests should be passed in via path or query params, so it's gettable from the browser
🙏 1
c

christophsturm

04/29/2021, 10:31 AM
its not only against rest conventions, its against the http standard
r

rsktash

04/29/2021, 10:31 AM
But other libs works with get request body
b

Big Chungus

04/29/2021, 10:33 AM
Ktor can do it too. It just doesn't expose dsl for it as it's an antipattern
c

christophsturm

04/29/2021, 10:33 AM
some http clients dont support it like okhttp or the javascript fetch api
“So, yes, you can send a body with GET, and no, it is never useful to do so.” https://stackoverflow.com/questions/978061/http-get-with-request-body
i know some rest apis that define get requests with bodies, but it has always worked for me to send the fields as query parameters instead
j

Joost Klitsie

04/29/2021, 12:29 PM
If there is too much data to be send out, it should be a POST
Too much data-> If it doesn't fit in the URL anymore 🙂
c

christophsturm

04/29/2021, 12:31 PM
if it changes state it should be a post or put.
b

Big Chungus

04/29/2021, 12:32 PM
Don't forget that url queries support lists too. I find that to be the main blocker for ppl not knowing it.
2 Views