package mason
Manage your REST resources with Mason.
More about HATEOAS : https://en.wikipedia.org/wiki/HATEOAS
Mason specs can be found here : https://github.com/JornWildt/Mason/blob/master/Documentation/Mason-draft-2.md
This library uses play-json : https://github.com/playframework/play-json
As for play-json, write an implicit schidaine.mason.MasonWrite in a companion object of your resource.
Example :
import play.api.libs.json._ import schidaine.mason._ case class MyObject(data: String) object MyObject extends MasonValues { implicit val masonWrite = new MasonWrite[MyObject] { def writes(o: MyObject) = Namespaces("ns1" -> "https://localhost/rels") ++ Json.obj("object" -> o.data) ++ Controls( "self" -> Link($.href := "https://localhost/my-object"), "ns1:add-description" -> Link($.href := "https://localhost/my-object/descriptions", $.encoding := JSON) ) } }
Use schidaine.mason.Mason object to manipulate a such resource.
Example :
val o = MyObject("Tardis") Mason.toJson(o)
See schidaine.mason.MasonKeyBuilder to see available properties (Mason specs are not yet fully implemented).
- Alphabetic
- By Inheritance
- mason
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- case class Controls(refs: (String, Link)*) extends MasonObject with Product with Serializable
Represents a @controls object as a collection of references.
Represents a @controls object as a collection of references.
Example:
val ctrl = Controls("self" -> Link($.href := "http://my.domain.io/my-resource"))
- trait Encodings extends AnyRef
Standard Encodings
- case class Error(message: Message, properties: OptionalErrorProperty*) extends MasonObject with Product with Serializable
Represents a @error object, only present in the root object
Represents a @error object, only present in the root object
- message
a mandatory errorMessage
- properties
optional properties ; in case of duplicated property names, the last one override the others.
- sealed trait ErrorProperty extends Property
Properties available in @error object
- case class GenericProperty(name: String, value: JsValue) extends MetaProperty with OptionalErrorProperty with Product with Serializable
A generic property allowing extension of @meta and @error objects
- class GenericPropertyBuilder extends AnyRef
Factory for GenericProperty
- trait HttpVerbs extends AnyRef
Standard HTTP Verbs
- case class JsonObject(value: JsObject) extends MasonObject with Product with Serializable
Any JsObject as a MasonObject
- case class Link(href: Href, properties: OptionalLinkProperty*) extends Product with Serializable
Represents a link object
Represents a link object
Example :
val link = Link($.href := "http://my.domain.io/my-resource", $.method := POST)
- href
a mandatory href property
- properties
optional link properties ; in case of duplicated property names, the last one override the others.
- sealed trait LinkProperty extends Property
Properties available in a link description
- trait MasonKeyBuilder extends AnyRef
DSL for Mason
DSL for Mason
Meta( $.metaTitle := "title", $.metaDescription := "a bigger description", $.property("extended") := "an extended field" $.relation("copyright") := Link( $.href := "/copyright" $.title := "Link to copyright information") )
- sealed trait MasonObject extends AnyRef
Represents any Mason object such as @controls, @meta, @error, @namespaces
- trait MasonValues extends Encodings with HttpVerbs with MediaType
Mason values : HttpVerbs, Encodings and so on
- trait MasonWrites[-A] extends AnyRef
Mason serializer: write an implicit to define a serializer for any type
Mason serializer: write an implicit to define a serializer for any type
- Annotations
- @implicitNotFound("No Mason serializer found for type ${A}. Try to implement an implicit MasonWrites for this type.")
- trait MediaType extends AnyRef
Mason media type
- case class Meta(properties: MetaProperty*) extends MasonObject with Product with Serializable
Represents a @meta object, only present in the root object
Represents a @meta object, only present in the root object
- properties
zero or more meta properties ; in case of duplicated property names, the last one override the others.
- sealed trait MetaProperty extends Property
Properties available in @meta object
- case class Namespaces(curies: (String, String)*) extends MasonObject with Product with Serializable
Represents a @namespaces object
Represents a @namespaces object
- curies
a list of (prefix, URI) elements
- trait Property extends Any
A basic Mason property
- trait PropertyBuilder[T] extends AnyRef
- case class Relation(name: String, link: Link) extends MetaProperty with OptionalErrorProperty with Product with Serializable
- case class RelationBuilder(name: String) extends PropertyBuilder[Link] with Product with Serializable
- case class RootObject(underlying: List[MasonObject]) extends Product with Serializable
Represents the root of a Mason object
Value Members
- val $: MasonKeyBuilder.type
A shortcut to schidaine.mason.MasonKeyBuilder, useful to create Mason Properties
- object Controls extends Serializable
Serializer for schidaine.mason.Controls
- object Encodings extends Encodings
Standard Encodings
- object Error extends Serializable
Serializer for schidaine.mason.Error
- object ErrorProperty
- object HttpVerbs extends HttpVerbs
Standard HTTP Verbs
- object JsonObject extends Serializable
Serializer and helpers for schidaine.mason.JsonObject
- object Link extends Serializable
Serializer for schidaine.mason.Link
- object LinkProperty
- object Mason
- object MasonKeyBuilder extends MasonKeyBuilder
- object MasonObject
Implicit conversions and serializer for schidaine.mason.MasonObject instances.
Implicit conversions and serializer for schidaine.mason.MasonObject instances.
import MasonObject._ val mason = Json.obj("data" -> "a small data") ++ Error($.errorMessage := "There is a big problem")
- object MasonValues extends MasonValues
Mason values : HttpVerbs, Encodings and so on
- object MasonWrites
- object MediaType extends MediaType
Mason media type
- object Meta extends Serializable
Serializer for schidaine.mason.Meta
- object MetaProperty
- object Namespaces extends Serializable
Serializer for schidaine.mason.Namespaces
- object Relation extends Serializable
- object RootObject extends Serializable
Factories and serialiser for schidaine.mason.RootObject