API | Status Codes |
---|---|
[Twitter][tw] | 200, 304, 400, 401, 403, 404, 406, 410, 420, 422, 429, 500, 502, 503, 504 |
[Stripe][stripe] | 200, 400, 401, 402, 404, 429, 500, 502, 503, 504 |
[Github][gh] | 200, 400, 422, 301, 302, 304, 307, 401, 403 |
[Pagerduty][pd] | 200, 201, 204, 400, 401, 403, 404, 408, 500 |
[NewRelic Plugins][nr] | 200, 400, 403, 404, 405, 413, 500, 502, 503, 503 |
[Etsy][etsy] | 200, 201, 400, 403, 404, 500, 503 |
[Dropbox][db] | 200, 400, 401, 403, 404, 405, 429, 503, 507 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[info] Benchmark Mode Cnt Score Error Units | |
[info] RerunnableBenchmark.sumIntsEF thrpt 40 45.180 ± 2.361 ops/s | |
[info] RerunnableBenchmark.sumIntsEF:·gc.alloc.rate.norm thrpt 40 45596119.411 ± 32.597 B/op | |
[info] RerunnableBenchmark.sumIntsF thrpt 40 63.038 ± 3.683 ops/s | |
[info] RerunnableBenchmark.sumIntsF:·gc.alloc.rate.norm thrpt 40 28796020.355 ± 23.283 B/op | |
[info] RerunnableBenchmark.sumIntsPF thrpt 40 22.371 ± 2.129 ops/s | |
[info] RerunnableBenchmark.sumIntsPF:·gc.alloc.rate.norm thrpt 40 52033222.296 ± 2995947.605 B/op | |
[info] RerunnableBenchmark.sumIntsPR thrpt 40 16.022 ± 1.675 ops/s | |
[info] RerunnableBenchmark.sumIntsPR:·gc.alloc.rate.norm t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.finch._ | |
import com.twitter.finagle.stats._ | |
// See https://github.com/finagle/finch/issues/552 | |
def time[A](stat: Stat, e: Endpoint[A]): Endpoint[A] = new Endpoint[A] { | |
def apply(: Input): Endpoint.Result[A] = { | |
e(i).map { | |
case (remainder, output) => remainder -> output.map { f => | |
Stat.timeFuture(stat)(f) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> case class Auth(u: String) | |
defined class Auth | |
scala> val auth = headerOption("Auth").withDefault("anon").as[Auth].mapOutput { a => | |
| if (a.u == "foo") Ok(a) else Unauthorized(new Exception("wrong credentials")) | |
| } | |
scala> val e = get("foo" :: auth).map(_.u) | |
e: io.finch.Endpoint[String] = GET /foo/header(Auth) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait Dict | |
object Dict { | |
// dict(“a”: “apple”, “b”: dict(“c”: “cat”, “d”: “dog”)) -> “{a:apple,b:{c:cat,d:dog}}” | |
case class Val(s: String) extends Dict | |
case class Obj(m: Map[String, Dict]) extends Dict | |
def encode(d: Dict): String = { | |
def loop(dd: Dict, sb: StringBuilder): StringBuilder = dd match { | |
case Val(s) => sb.append(s) | |
case Obj(m) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.finch._ | |
import com.twitter.finagle.http.Status | |
import io.circe._ | |
import io.circe.generic.auto._ | |
import io.finch.circe._ | |
// Here we tell Finch how to encode exceptions to send them over the wire. | |
val e: Encoder[Exception] = Encoder.instance { | |
case ce: MyError => MyError.jsonEncoder(ce) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> trait Foo1; trait Foo2 | |
defined trait Foo1 | |
defined trait Foo2 | |
scala> trait Bar1; trait Bar2; | |
defined trait Bar1 | |
defined trait Bar2 | |
scala> object Foo { | |
| val endpoints = Endpoint(Ok(new Foo1{})) :+: Endpoint(Ok(new Foo2{})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twitter.finagle.Http | |
import com.twitter.util.{Future, Await} | |
import io.finch._ | |
object Test1 extends App { | |
implicit val encodeMap: EncodeResponse[Map[String, String]] = | |
EncodeResponse("text/plain")(map => | |
Buf.Utf8(map.toSeq.map(kv => kv._1 + ":" + kv._2).mkString("\n")) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Migrate to Finagle 6.30 https://groups.google.com/forum/#!topic/finaglers/skmdgDhcP0c | |
git grep -lz 'finagle.httpx' | xargs -0 sed -i '' -e 's/finagle.httpx/finagle.http/g' | |
git grep -lz 'Httpx' | xargs -0 sed -i '' -e 's/Httpx/Http/g' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def auth0[A, B](doAuth: Request => Future[A])(e: Endpoint[B])(implicit | |
adjoin: PairAdjoin[A, B] | |
): Endpoint[adjoin.Out] = new Endpoint[adjoin.Out] { | |
def apply(input: Input): Option[(Input, () => Future[Output[adjoin.Out]])] = | |
e(input).map { | |
case (remainder, output) => | |
(remainder, () => for { | |
a <- doAuth(input.request) | |
ob <- output() | |
} yield b.copy(value = adjoin(a, b.value))) |