blob: 2b01e839812b96e08a041bc98eeb0bcb07eec522 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package com.softwaremill.sttp
import java.io.{File, InputStream}
import java.nio.ByteBuffer
import java.nio.file.Path
import scala.language.higherKinds
package object model {
case class Method(m: String) extends AnyVal
object Method {
val GET = Method("GET")
val HEAD = Method("HEAD")
val POST = Method("POST")
val PUT = Method("PUT")
val DELETE = Method("DELETE")
val OPTIONS = Method("OPTIONS")
val PATCH = Method("PATCH")
val CONNECT = Method("CONNECT")
val TRACE = Method("TRACE")
}
/**
* Provide an implicit value of this type to serialize arbitrary classes into a request body.
* Handlers might also provide special logic for serializer instances which they define (e.g. to handle streaming).
*/
type BodySerializer[T] = T => BasicRequestBody
sealed trait RequestBody
case object NoBody extends RequestBody
case class SerializableBody[T](f: BodySerializer[T], t: T) extends RequestBody
sealed trait BasicRequestBody extends RequestBody
case class StringBody(s: String, encoding: String) extends BasicRequestBody
case class ByteArrayBody(b: Array[Byte]) extends BasicRequestBody
case class ByteBufferBody(b: ByteBuffer) extends BasicRequestBody
case class InputStreamBody(b: InputStream) extends BasicRequestBody
case class FileBody(f: File) extends BasicRequestBody
case class PathBody(f: Path) extends BasicRequestBody
/**
* @tparam T Target type as which the response will be read.
* @tparam S If `T` is a stream, the type of the stream. Otherwise, `Nothing`.
*/
sealed trait ResponseAs[T, +S]
object IgnoreResponse extends ResponseAs[Unit, Nothing]
case class ResponseAsString(encoding: String) extends ResponseAs[String, Nothing]
object ResponseAsByteArray extends ResponseAs[Array[Byte], Nothing]
// response as params
case class ResponseAsStream[T, S]()(implicit val responseIsStream: S =:= T) extends ResponseAs[T, S]
}
|