From b52535375b7c14942916e79ad3c7cd35dd0696b5 Mon Sep 17 00:00:00 2001 From: sleefd Date: Sat, 9 Dec 2023 14:28:26 +0800 Subject: [PATCH] add an api project to showcase --- src/sbt-test/sbt-curl/api/build.sbt | 11 ++++++++ src/sbt-test/sbt-curl/api/curl-test | 6 ++++ src/sbt-test/sbt-curl/api/project/plugins.sbt | 1 + .../sbt-curl/api/src/main/scala/Api.scala | 28 +++++++++++++++++++ src/sbt-test/sbt-curl/api/test | 4 +++ 5 files changed, 50 insertions(+) create mode 100644 src/sbt-test/sbt-curl/api/build.sbt create mode 100644 src/sbt-test/sbt-curl/api/curl-test create mode 100644 src/sbt-test/sbt-curl/api/project/plugins.sbt create mode 100644 src/sbt-test/sbt-curl/api/src/main/scala/Api.scala create mode 100644 src/sbt-test/sbt-curl/api/test diff --git a/src/sbt-test/sbt-curl/api/build.sbt b/src/sbt-test/sbt-curl/api/build.sbt new file mode 100644 index 0000000..1cd5fb6 --- /dev/null +++ b/src/sbt-test/sbt-curl/api/build.sbt @@ -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" + ) + ) diff --git a/src/sbt-test/sbt-curl/api/curl-test b/src/sbt-test/sbt-curl/api/curl-test new file mode 100644 index 0000000..40b0795 --- /dev/null +++ b/src/sbt-test/sbt-curl/api/curl-test @@ -0,0 +1,6 @@ +# single line curl command +curl http://localhost:8080/ping + +# multiline curl command +curl -X POST \ +http://localhost:8080/uuid diff --git a/src/sbt-test/sbt-curl/api/project/plugins.sbt b/src/sbt-test/sbt-curl/api/project/plugins.sbt new file mode 100644 index 0000000..3a980d7 --- /dev/null +++ b/src/sbt-test/sbt-curl/api/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("me.yceel" % "sbt-curl" % System.getProperty("plugin.version")) diff --git a/src/sbt-test/sbt-curl/api/src/main/scala/Api.scala b/src/sbt-test/sbt-curl/api/src/main/scala/Api.scala new file mode 100644 index 0000000..417e501 --- /dev/null +++ b/src/sbt-test/sbt-curl/api/src/main/scala/Api.scala @@ -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) + } +} \ No newline at end of file diff --git a/src/sbt-test/sbt-curl/api/test b/src/sbt-test/sbt-curl/api/test new file mode 100644 index 0000000..83c8d80 --- /dev/null +++ b/src/sbt-test/sbt-curl/api/test @@ -0,0 +1,4 @@ +# start server +> run +# run curl commands in curl-test +> curlTest \ No newline at end of file