io.fintrospect.parameters.Body.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fintrospect_2.10 Show documentation
Show all versions of fintrospect_2.10 Show documentation
Library that adds self-documentation to Finagle server endpoint services
package io.fintrospect.parameters
import com.twitter.finagle.http.Message
import io.fintrospect.ContentType
import io.fintrospect.formats.json.{Argo, JsonFormat}
import scala.xml.Elem
abstract class Body[T](spec: BodySpec[T]) extends Iterable[BodyParameter] with Mandatory[Message, T]
with Extractable[Message, T] {
val contentType: ContentType = spec.contentType
}
/**
* Factory methods for various supported HTTP body types.
*/
object Body {
/**
* Create a custom body type for the request. Encapsulates the means to insert/retrieve into the request
*/
def apply[T](bodySpec: BodySpec[T], example: T = null, paramType: ParamType = StringParamType): UniBody[T] = new UniBody[T](bodySpec, paramType, Option(example))
/**
* JSON format HTTP message body. Defaults to Argo JSON format, but this can be overridden by passing an alternative JsonFormat
*/
def json[T](description: Option[String], example: T = null, jsonFormat: JsonFormat[T, _] = Argo.JsonFormat): UniBody[T] = Body(BodySpec.json(description, jsonFormat), example, ObjectParamType)
/**
* Native Scala XML format HTTP message body.
*/
def xml(description: Option[String], example: Elem = null): UniBody[Elem] = Body(BodySpec.xml(description), example, StringParamType)
/**
* HTML encoded form HTTP message body.
*/
def form(fields: FormField[_] with Retrieval[Form, _] with Extractable[Form, _]*): FormBody = new FormBody(fields)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy