-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial steps for http integration (#203)
- Loading branch information
1 parent
8ec1650
commit edca907
Showing
7 changed files
with
184 additions
and
1 deletion.
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,20 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.rpc.http | ||
package server | ||
|
||
final case class HttpConfig(host: String, port: Int) |
31 changes: 31 additions & 0 deletions
31
modules/http/server/src/main/scala/HttpServerBuilder.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,31 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.rpc.http | ||
package server | ||
|
||
import cats.effect.Effect | ||
import monix.execution.Scheduler | ||
import org.http4s.HttpService | ||
import org.http4s.server.blaze.BlazeBuilder | ||
|
||
class HttpServerBuilder[F[_]: Effect](implicit C: HttpConfig, S: Scheduler) { | ||
|
||
def build(service: HttpService[F], prefix: String = "/"): BlazeBuilder[F] = | ||
BlazeBuilder[F] | ||
.bindHttp(C.port, C.host) | ||
.mountService(service, prefix) | ||
} |
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,35 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.rpc.http | ||
package server | ||
|
||
import cats.effect.Effect | ||
import fs2.{Stream, StreamApp} | ||
import monix.execution.Scheduler | ||
import org.http4s.HttpService | ||
|
||
object HttpServerStream { | ||
|
||
def apply[F[_]: Effect](service: HttpService[F], prefix: String = "/")( | ||
implicit C: HttpConfig, | ||
S: Scheduler): Stream[F, StreamApp.ExitCode] = { | ||
val httpServerBuilder: HttpServerBuilder[F] = new HttpServerBuilder[F] | ||
|
||
httpServerBuilder.build(service, prefix).serve | ||
} | ||
|
||
} |
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,33 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.rpc.http | ||
package server | ||
|
||
import cats.effect.Effect | ||
import monix.execution.Scheduler | ||
import org.http4s.HttpService | ||
import org.http4s.dsl.Http4sDsl | ||
|
||
class ExampleService[F[_]: Effect] extends Http4sDsl[F] { | ||
|
||
def service(implicit scheduler: Scheduler): HttpService[F] = | ||
HttpService[F] { | ||
case GET -> Root / "ping" => | ||
Ok("pong") | ||
} | ||
|
||
} |
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,45 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.rpc.http | ||
package server | ||
|
||
import cats.effect.IO | ||
import monix.execution.Scheduler | ||
import org.http4s.HttpService | ||
import org.scalatest.{Assertion, Matchers, WordSpec} | ||
|
||
class HttpServerTests extends WordSpec with Matchers { | ||
|
||
implicit val S: Scheduler = monix.execution.Scheduler.Implicits.global | ||
implicit val C: HttpConfig = HttpConfig("0.0.0.0", 8090) | ||
|
||
val service: HttpService[IO] = new ExampleService[IO].service | ||
val prefix: String = "/" | ||
|
||
def ok: Assertion = 1 shouldBe 1 | ||
|
||
"HttpServerBuilder.build" should { | ||
|
||
"work as expected" in { | ||
|
||
new HttpServerBuilder[IO].build(service, prefix) | ||
|
||
ok | ||
} | ||
|
||
} | ||
} |
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