Custom byContent handler

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom byContent handler

zedar185
Hi, what is the best way to define custom byContent handler?
For example for handling “Accept: application/hal+json” type.
Reply | Threaded
Open this post in threaded view
|

Re: Custom byContent handler

Luke Daley
Administrator
You can use the type() method: http://www.ratpack.io/manual/current/api/ratpack/handling/ByContentSpec.html#type(java.lang.String, ratpack.handling.Handler)

Handler handler = ctx -> {
  ctx.byContent(s -> s
    .type("application/hal+json”, ctx -> ctx.render(…))
}

Or if you’re using Groovy:

http://www.ratpack.io/manual/current/api/ratpack/groovy/handling/GroovyByContentSpec.html#type(java.lang.String, groovy.lang.Closure)

handler {
  byContent {
    type("application/hal+json") {
      render …
    }
  }