Skip to content

Commit

Permalink
add an api project to showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
reminia committed Dec 9, 2023
1 parent f1fe80e commit b525353
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/sbt-test/sbt-curl/api/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
val AkkaHttpVersion = "10.5.3"

lazy val root = (project in file("."))
.settings(
version := "0.1",
resolvers += "Akka repo".at("https://repo.akka.io/maven"),
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % "2.7.0"
)
)
6 changes: 6 additions & 0 deletions src/sbt-test/sbt-curl/api/curl-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# single line curl command
curl http://localhost:8080/ping

# multiline curl command
curl -X POST \
http://localhost:8080/uuid
1 change: 1 addition & 0 deletions src/sbt-test/sbt-curl/api/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("me.yceel" % "sbt-curl" % System.getProperty("plugin.version"))
28 changes: 28 additions & 0 deletions src/sbt-test/sbt-curl/api/src/main/scala/Api.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives

import java.util.UUID

object Api extends Directives {
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem("api")

val router = concat(
path("ping") {
get {
complete(200, "I'm up!")
}
},
path("uuid") {
post {
val uuid = UUID.randomUUID()
complete(200, uuid.toString)
}
}
)

val port = sys.props.getOrElse("http.port", "8080").toInt
Http().newServerAt("0.0.0.0", port).bind(router)
}
}
4 changes: 4 additions & 0 deletions src/sbt-test/sbt-curl/api/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# start server
> run
# run curl commands in curl-test
> curlTest

0 comments on commit b525353

Please sign in to comment.