Created
June 8, 2020 18:38
-
-
Save 2013techsmarts/74f535e3bdcd643b7eb4ca8bb45c3750 to your computer and use it in GitHub Desktop.
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
package org.smarttechie.router; | |
import org.smarttechie.handler.ProductHandler; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.http.MediaType; | |
import org.springframework.web.reactive.function.server.RouterFunction; | |
import org.springframework.web.reactive.function.server.RouterFunctions; | |
import org.springframework.web.reactive.function.server.ServerResponse; | |
import static org.springframework.web.reactive.function.server.RequestPredicates.*; | |
@Configuration | |
public class ProductRouter { | |
/** | |
* The router configuration for the product handler. | |
* @param productHandler | |
* @return | |
*/ | |
@Bean | |
public RouterFunction<ServerResponse> productsRoute(ProductHandler productHandler){ | |
return RouterFunctions | |
.route(GET("/products").and(accept(MediaType.APPLICATION_JSON)) | |
,productHandler::getAllProducts) | |
.andRoute(POST("/product").and(accept(MediaType.APPLICATION_JSON)) | |
,productHandler::createProduct) | |
.andRoute(DELETE("/product/{id}").and(accept(MediaType.APPLICATION_JSON)) | |
,productHandler::deleteProduct) | |
.andRoute(PUT("/product/{id}").and(accept(MediaType.APPLICATION_JSON)) | |
,productHandler::updateProduct); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment