-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added scala/http4s. Closes #336 * minor * add http4s on framework list
- Loading branch information
Showing
9 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target/ | ||
project/project | ||
project/target | ||
*.class |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM bigtruedata/sbt | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY build.sbt ./ | ||
COPY src src | ||
COPY project project | ||
|
||
RUN sbt assembly | ||
|
||
EXPOSE 3000 | ||
|
||
CMD java -jar target/scala-2.12/*assembly*.jar |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
val Http4sVersion = "0.18.17" | ||
|
||
lazy val root = (project in file(".")) | ||
.settings( | ||
organization := "the.benchmarker", | ||
name := "http4s", | ||
version := "0.0.1-SNAPSHOT", | ||
scalaVersion := "2.12.6", | ||
libraryDependencies ++= Seq( | ||
"org.http4s" %% "http4s-blaze-server" % Http4sVersion, | ||
"org.http4s" %% "http4s-circe" % Http4sVersion, | ||
"org.http4s" %% "http4s-dsl" % Http4sVersion | ||
) | ||
) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.4") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sbt.version=0.13.15 | ||
|
24 changes: 24 additions & 0 deletions
24
scala/http4s/src/main/scala/the/benchmarker/http4s/HelloWorldServer.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package the.benchmarker.http4s | ||
|
||
import cats.effect.{Effect, IO} | ||
import fs2.StreamApp | ||
import org.http4s.server.blaze.BlazeBuilder | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
object HelloWorldServer extends StreamApp[IO] { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
def stream(args: List[String], requestShutdown: IO[Unit]) = ServerStream.stream[IO] | ||
} | ||
|
||
object ServerStream { | ||
|
||
def helloWorldService[F[_]: Effect] = new HelloWorldService[F].service | ||
|
||
def stream[F[_]: Effect](implicit ec: ExecutionContext) = | ||
BlazeBuilder[F] | ||
.bindHttp(3000, "0.0.0.0") | ||
.mountService(helloWorldService, "/") | ||
.serve | ||
} |
20 changes: 20 additions & 0 deletions
20
scala/http4s/src/main/scala/the/benchmarker/http4s/HelloWorldService.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package the.benchmarker.http4s | ||
|
||
import cats.effect.Effect | ||
import io.circe.Json | ||
import org.http4s.HttpService | ||
import org.http4s.dsl.Http4sDsl | ||
|
||
class HelloWorldService[F[_]: Effect] extends Http4sDsl[F] { | ||
|
||
val service: HttpService[F] = { | ||
HttpService[F] { | ||
case GET -> Root => | ||
Ok("") | ||
case POST -> Root / "user" => | ||
Ok("") | ||
case GET -> Root / "user" / name => | ||
Ok(name) | ||
} | ||
} | ||
} |
This file contains 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