Skip to content

Instantly share code, notes, and snippets.

@devnulled
Created September 17, 2012 21:19
Show Gist options
  • Select an option

  • Save devnulled/3739869 to your computer and use it in GitHub Desktop.

Select an option

Save devnulled/3739869 to your computer and use it in GitHub Desktop.
Simple Helper Class to return JSON Responses in Lift with a particular HTTP Status Code
package your.mom
import net.liftweb.http.{S, HeaderDefaults, InMemoryResponse, LiftResponse}
import net.liftweb.json.JsonAST.JValue
import net.liftweb.json._
// This is much nicer to use than the native JsonResponse in Lift
case class WrappedLiftJsonResponse(json: JValue, statusCode: Int, respHeaders: List[(String, String)] = Nil) extends LiftResponse with HeaderDefaults {
val headerContentType = "Content-Type"
val headerJsonContentValue = "application/json"
def toResponse = {
val jsonHeader = List((headerContentType, headerJsonContentValue))
val jsonString = compact(render(json))
InMemoryResponse(jsonString.getBytes("UTF-8"), jsonHeader ++ respHeaders, cookies, statusCode)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment