dave
02/23/2018, 3:05 PMfun add(value1: Int, value2: Int): HttpHandler = {
Response(OK).with(
Body.string(TEXT_PLAIN).toLens() of (value1 + value2).toString()
)}
val contract = contract(OpenApi(ApiInfo("my great api", "v1.0"), Argo),
"/add" / <http://Path.int|Path.int>().of("value1") / Path.fixed("hello") / <http://Path.int|Path.int>().of("value2") meta {
summary = "add"
description = "Adds 2 numbers together"
returning("The result" to OK)
} bindContract GET
to { a, _, c -> add(a, c) }
)
contract.asServer(Jetty(8000)).start()
elifarley
02/23/2018, 4:39 PMdave
02/23/2018, 4:41 PMelifarley
02/23/2018, 4:46 PMdave
02/23/2018, 5:06 PM/sgzr/api/v1
elifarley
02/23/2018, 5:08 PMRESPONSE 404 to GET: /sgzr/api/v1/
However:
RESPONSE 200 to GET: /sgzr/api/v1/catalogs/x/products
dave
02/23/2018, 5:15 PMelifarley
02/23/2018, 5:35 PMdave
02/23/2018, 5:36 PMval productsRoute: RouteBinder<(String, String) -> HttpHandler> =
"/catalogs" / Path.string().of("catalog-name", "Catalog name ('Client-Realm-Id' in headers)") /
Path.fixed("products") meta {
summary = "Get products from a catalog given a catalog name"
} bindContract GET
val sgzrHandler: RoutingHttpHandler = routes(
"/sgzr/api/v1" bind contract(OpenApi(ApiInfo("Stargazer-O API", "v1.0"), Argo), "", NoSecurity,
productsRoute to { a, _ -> { Response(OK) } }
)
)
sgzrHandler.asServer(Jetty(8000)).start()
elifarley
02/23/2018, 5:36 PMdave
02/23/2018, 5:38 PMfun contract(renderer: ContractRenderer = NoRenderer, descriptionPath: String = "", security: Security = NoSecurity, vararg serverRoutes: ContractRoute) =
ContractRoutingHttpHandler(renderer, security, descriptionPath, "", serverRoutes.map { it })
elifarley
02/23/2018, 5:38 PMdave
02/23/2018, 5:39 PMelifarley
02/23/2018, 6:17 PM