Giter Club home page Giter Club logo

validation's Introduction

The unified data validation library

Overview

The unified validation API aims to provide a comprehensive toolkit to validate data from any format against user defined rules, and transform them to other types.

Basically, assuming you have this:

import play.api.libs.json._
import play.api.data.mapping._

case class Person(name: String, age: Int, lovesChocolate: Boolean)

val json = Json.parse("""{
  "name": "Julien",
  "age": 28,
  "lovesChocolate": true
}""")

implicit val personRule = {
  import play.api.data.mapping.json.Rules._
  Rule.gen[JsValue, Person]
}

It can do this:

scala> personRule.validate(json)
res0: play.api.data.mapping.VA[Person] = Success(Person(Julien,28,true))

BUT IT'S NOT LIMITED TO JSON

It's also a unification of play's Form Validation API, and its Json validation API.

Being based on the same concepts as play's Json validation API, it should feel very similar to any developer already working with it. The unified validation API is, rather than a totally new design, a simple generalization of those concepts.

Design

The unified validation API is designed around a core defined in package play.api.data.mapping, and "extensions". Each extension provides primitives to validate and serialize data from / to a particular format (Json, form encoded request body, etc.). See the extensions documentation for more information.

To learn more about data validation, please consult Validation and transformation with Rule, for data serialization read Serialization with Write. If you just want to figure all this out by yourself, please see the Cookbook.

Using the validation api in your project

Add the following lines in your build.sbt

resolvers += Resolver.sonatypeRepo("releases")

// If you want only the core
libraryDependencies +="io.github.jto" %% "validation-core" % "1.1"

// Json validation for play-json
libraryDependencies +="io.github.jto" %% "validation-json" % "1.1"

// Json validation for json4s
libraryDependencies += "io.github.jto" %% "validation-json4s" % "1.1"

// Form validation
libraryDependencies +="io.github.jto" %% "validation-form" % "1.1"

// XML validation
libraryDependencies +="io.github.jto" %% "validation-xml % "1.1"

Play dependency

The 1.1.X versions are builded with play 2.4, if you are using play 2.3 you need to use the 1.0.2 version.

Documentation

All the required documentation is directly readable from Github: https://github.com/jto/validation/tree/master/documentation/tut

Contributors

validation's People

Contributors

jto avatar atamborrino avatar stanch avatar themodernlife avatar olivierblanvillain avatar ast-pellucid avatar gbougeard avatar bthuillier avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.