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

Dariusz Kuc

03/06/2023, 11:43 PM
👋 whats the proper way to configure accept multiple content types on a server route (and fallback to json if none specified)?
Copy code
accept(ContentType) {
  // configure route
  post("foo") {...}
}
// configure same route as above?
post("foo") {...}
seems pretty redundant....
o

Olivier Patry

03/07/2023, 6:48 AM
d

Dariusz Kuc

03/07/2023, 7:09 PM
to an extent yeah I think I could do something like this
Copy code
val route = post("foo") { ... }
route.install(ContentNegotiation) {
  jackson(contentType = ContentType.parse("application/graphql-response+json")) 
  // fallback
  jackson(contentType = ContentType.Any)
}
thanks!
3 Views