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

robin

09/05/2018, 3:12 PM
I can't find a way to do HEAD and OPTIONS requests via ktor-client - are these actually missing, or did I just look in the wrong place? I'd have expected them to look like
httpClient.head(url)
, just like
httpClient.get(url)
does
📝 1
1
d

Deactivated User

09/05/2018, 3:23 PM
You can use
call
, and `request`: https://ktor.io/clients/http-client/calls/requests.html#custom-requests and set the
method = HttpMethod.YourMethod
I think there are no shortcuts for other verbs other than get and post
But you can include them in your code if you want
just copy the get or post extension methods and adjust accordingly
r

r4zzz4k

09/05/2018, 3:25 PM
There are also
.put
and
.delete
there, but no head and options shortlands. Was just printing the answer with this link 🙂 https://github.com/ktorio/ktor/blob/a65667a6f0ca98128c38025f989bad7cb6da4576/ktor-client/ktor-client-core/src/io/ktor/client/request/builders.kt#L65
d

Deactivated User

09/05/2018, 3:25 PM
oh, right,then I have to update the documentation 🙂
😄 1
r

robin

09/05/2018, 3:27 PM
Thanks, that helped! So does anyone know if there's a specific reason for omitting just these two verbs from the shorthands? Should be simple enough to patch them in
d

Deactivated User

09/05/2018, 3:30 PM
probably no specific reason, I guess, just not done 🙂 but @e5l can you confirm?
e

e5l

09/05/2018, 3:32 PM
The
head
and
options
methods has specific semantic in http and I consider to hide them from the simple builders.
👌 1
You could always set the
HttpMethod
in
call
and
request
methods.
d

Deactivated User

09/05/2018, 3:36 PM
I have updated the documentation to reflect all the things we have talked about: https://ktor.io/clients/http-client/calls/requests.html#shortcut-methods
🙏 1
4 Views