Creates a GET request to the given uri and opts.
Creates a GET request to the given uri and opts.
scala> import hammock._, hammock.jvm.Interpreter, hammock.hi._, hammock.hi._, cats._, cats.implicits._, scala.util.Try import hammock._ import hammock.jvm.Interpreter import hammock.hi._ import hammock.hi._ import cats._ import cats.implicits._ import scala.util.Try scala> val opts = (header("X-Test" -> "works!") >>> auth(Auth.BasicAuth("user", "pass")) >>> cookie(Cookie("key", "value")))(Opts.empty) opts: hammock.hi.Opts = Opts(Some(BasicAuth(user,pass)),Map(X-Test -> works!),Some(List(Cookie(key,value,None,None,None,None,None,None,None,None)))) scala> Hammock.getWithOpts(uri"http://httpbin.org/get", opts) res1: Free[HttpF, hammock.HttpResponse] = Free(...)
Creates a HEAD request to the given uri and opts.
Creates a HEAD request to the given uri and opts.
import hammock._ import hammock.jvm.Interpreter import hammock.hi._ import hammock.hi._ import cats._ import cats.implicits._ import scala.util.Try val opts = (header("X-Test" -> "works!") >>> auth(Auth.BasicAuth("user", "pass")) >>> cookie(Cookie("key", "value")))(Opts.empty) Hammock.headWithOpts(uri"http://httpbin.org/get", opts)
Creates an OPTIONS request to the given uri and opts.
Creates an OPTIONS request to the given uri and opts.
scala> import hammock._, hammock.jvm.Interpreter, hammock.hi._, hammock.hi._, cats._, cats.implicits._, scala.util.Try import hammock._ import hammock.jvm.Interpreter import hammock.hi._ import hammock.hi._ import cats._ import cats.implicits._ import scala.util.Try scala> val opts = (header("X-Test" -> "works!") >>> auth(Auth.BasicAuth("user", "pass")) >>> cookie(Cookie("key", "value")))(Opts.empty) opts: hammock.hi.Opts = Opts(Some(BasicAuth(user,pass)),Map(X-Test -> works!),Some(List(Cookie(key,value,None,None,None,None,None,None,None,None)))) scala> Hammock.optionsWithOpts(uri"http://httpbin.org/get", opts) res1: Free[HttpF, hammock.HttpResponse] = Free(...)
Creates a POST request to the given uri and opts.
Creates a POST request to the given uri and opts. It also has an optional body parameter that can be used.
import hammock._ import hammock.jvm.Interpreter import hammock.hi._ import hammock.hi._ import cats._ import cats.implicits._ import scala.util.Try val opts = (header("X-Test" -> "works!") >>> auth(Auth.BasicAuth("user", "pass")) >>> cookie(Cookie("key", "value")))(Opts.empty) implicit val stringCodec = new Codec[String] { def encode(s: String) = s def decode(s: String) = Right(s) } Hammock.postWithOpts(uri"http://httpbin.org/get", opts, Some("""{"body": true}"""))
Creates a PUT request to the given uri and opts.
Creates a PUT request to the given uri and opts. It also has an optional body parameter that can be used.
import hammock._ import hammock.jvm.Interpreter import hammock.hi._ import hammock.hi._ import cats._ import cats.implicits._ import scala.util.Try val opts = (header("X-Test" -> "works!") >>> auth(Auth.BasicAuth("user", "pass")) >>> cookie(Cookie("key", "value")))(Opts.empty) implicit val stringCodec = new Codec[String] { def encode(s: String) = s def decode(s: String) = Right(s) } Hammock.postWithOpts(uri"http://httpbin.org/get", opts, Some("""{"body": true}"""))
similar to request, but you can pass it a body when it exists an instance for the Codec typeclass for the given type A
Creates an HttpF and from the Method, Uri, and String] headers.
Variant of withOpts methods that also takes an optional body of a request.
Variant of withOpts methods that also takes an optional body of a request. There should be a Codec instance for the body type for this to work.
Hammock.withOpts
Creates a request value given a method, uri, and opts, and suspends it into a cats.free.Free.
Creates a request value given a method, uri, and opts, and suspends it into a cats.free.Free.
Usage:
scala> import hammock._, hammock.jvm.Interpreter, hammock.hi._, hammock.hi._, cats._, cats.implicits._, scala.util.Try import hammock._ import hammock.jvm.Interpreter import hammock.hi._ import hammock.hi._ import cats._ import cats.implicits._ import scala.util.Try scala> val opts = (header("X-Test" -> "works!") >>> auth(Auth.BasicAuth("user", "pass")) >>> cookie(Cookie("key", "value")))(Opts.empty) opts: hammock.hi.Opts = Opts(Some(BasicAuth(user,pass)),Map(X-Test -> works!),Some(List(Cookie(key,value,None,None,None,None,None,None,None,None)))) scala> val response = Hammock.withOpts(Method.GET, uri"http://httpbin.org/get", opts) response: Free[HttpF, hammock.HttpResponse] = Free(...)