Integrations

Unfiltered

Grab argonaut-unfiltered by adding the following dependency to sbt:

"io.argonaut" %% "argonaut-unfiltered" % "6.1"

Use JsonRequest to wrap the HttpRequest. This produces an API equivelant to ParseWrap/StringWrap in core argonaut.

Use JsonResponse to wrap any data type than can be encoded (i.e. defines an instance for EncodeJson). JsonResponse will set the correct content-type, encode and print the json for your data.

A complete example.

import argonaut._, Argonaut._
import argonaut.integrate.unfiltered._
import unfiltered.request._
import unfiltered.response._

class App extends unfiltered.filter.Plan {

  case class Data(value: String)

  implicit def DataCodecJson: CodecJson[Data] =
    casecodec1(Data.apply, Data.unapply)("data")

  def intent = {
    case req@ Get("/echo") =>
      JsonRequest(req).decodeOption[Data] match {
        case None => BadRequest
        case Some(data) => Ok ~> JsonResponse(data)
      }
    }
  }