Skip to content

Commit

Permalink
readme, intellij http, webflux endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Kowalski committed Jun 25, 2018
1 parent fd6245a commit 4a0d5c1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
Agenda
======
- Intro
- Problem specification (solution FP with Spring)
* fp/spring
- Intro to Scala
* test/fp/basics
* test/fp/typeclasses/MaybeSpec
- Get to know your Typeclasses
* fp/typeclasses/
* ShowSpec
* EqSpec
* CsvEncoderSpec
- FP patterns
* fp/typeclasses/


Basic scala
===========
(types.scala)
Expand Down
11 changes: 11 additions & 0 deletions Service.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
GET http://localhost:8080/user/124
Accept: application/json

###

POST http://localhost:8080/user
Content-Type: application/json

{"userId": "124", "name": "maciej", "age": 23}

###
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.1.5
sbt.version=1.1.6
30 changes: 15 additions & 15 deletions src/main/scala/fp/spring/springfp/SpringWebFluxApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter
import org.springframework.web.reactive.function.BodyExtractors
import org.springframework.web.reactive.function.server.RequestPredicates.{GET, POST}
import org.springframework.web.reactive.function.server.RouterFunctions.route
import org.springframework.web.reactive.function.server.{
HandlerStrategies,
RouterFunction,
RouterFunctions,
ServerResponse
}
import org.springframework.web.reactive.function.server.{HandlerStrategies, RouterFunction, RouterFunctions, ServerResponse}
import reactor.core.publisher.Mono
import reactor.ipc.netty.NettyContext
import reactor.ipc.netty.http.server.HttpServer

class SpringWebFluxApp {

def start(port: Int) = {
def start(routing: RouterFunction[ServerResponse], port: Int): NettyContext = {

def runServer(router: RouterFunction[ServerResponse]) = {
val objectMapper = new ObjectMapper()
Expand All @@ -42,30 +38,34 @@ class SpringWebFluxApp {
server.newHandler(adapter)
}

// setup
// import infra.Sync._ // uncomment this line for synchronous interpretation

import infra.AsyncDomain._ // use asynchronous interpreter

val server = runServer(SpringWebFluxApp.routing(controller))
val server = runServer(routing)

server.block()
}
}

object SpringWebFluxApp extends App {
new SpringWebFluxApp().start(8080)
// val routing = routingBuilder(infra.AsyncDomain.controller)(infra.AsyncDomain.idMonoNat)

val routing = routingBuilder(infra.Sync.controller)(infra.Sync.idMonoNat)

new SpringWebFluxApp().start(routing, port = 8080)

System.out.println("Press ENTER to exit.")
System.in.read()

def routing[F[_]](controller: UserController[F])(implicit nat: ~>[F, Mono]): RouterFunction[ServerResponse] = {
def routingBuilder[F[_]](controller: UserController[F])(implicit nat: ~>[F, Mono]): RouterFunction[ServerResponse] = {
route(
GET("/user/{userId}/age"),
request => {
val userId = request.pathVariable("userId")
ServerResponse.ok().body(nat(controller.functorRequired(userId)), classOf[Int])
}
).andRoute(GET("/user/{userId}"),
request => {
val userId = request.pathVariable("userId")
ServerResponse.ok().body(nat(controller.get(userId)), classOf[User])
}
).andRoute(
POST("/user"),
request => {
Expand Down

0 comments on commit 4a0d5c1

Please sign in to comment.