Skip to content
An implementation for application/problem+json for the play framework
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project
src
.gitignore initial commit Jul 20, 2017
.scalafmt.conf
LICENSE
README.md
build.sbt updated to play 2.7.0 Apr 11, 2019
codestyle.sbt updated sbt plugin versions Apr 11, 2019
version.sbt

README.md

application/problem+json (RFC7807) plugin for Play framework

This plugin adds easy support for RFC7807 to your application.

Usage

add the dependency

libraryDependencies += "de.lenabrueder" %% "play-rfc7807" % "2.6.1"

to your build.sbt. Versioning follows play version in major and minor versions, patch version is up to the library. If you want to use the error handler as well, add

play.http.errorHandler = "de.lenabrueder.rfc7807.ProblemErrorHandler"

to your application.conf.

After that, you can use it through adding import de.lenabrueder.rfc7807.PlayIntegration._ to your controller. This adds some implicit functions to your Results, which allow you to do the following:

InternalServerError.withProblem("cannot store flight")
NotFound.asProblem
Forbidden.withProblem(new RuntimeException("something went wrong"))
Unauthorized.withProblem(Problem("https://httpstatuses.com/401", "no authorization"))

Result will be something like

{
  "type": "https://httpstatuses.com/404",
  "title": "Cannot find requested object",
  "status": 404
}

You can configure URL generation by changing the import import de.lenabrueder.rfc7807.PlayIntegration._ to import de.lenabrueder.rfc7807.PlayIntegration.ResultAsProblem and providing an instance of UrlConfiguration implicitly when calling the withProblem or asProblem functions.

You can’t perform that action at this time.