Search code examples
javahttpakka

can we have a default parameter in java akka http?


like below code

                 post(() -> route(
                    pathPrefix("scheduleStatus", () ->
                            path("send", () ->
                                    parameter("type", type ->
                                            entity(Jackson.unmarshaller(Car.class), car -> {
                                                return complete(car.getColor());
                                            })
                                    )

                            )
                    ))

can we have default value for type? like we think default car type is bmw etc? how can we achieve this in java akka http?


Solution

  • Akkording to the documentation you cannot do it with parameter() - you need to use parameterOptional():

        post(() -> route(
            pathPrefix("scheduleStatus", () ->
                path("send", () ->
                    parameterOptional("type", type ->
                        entity(Jackson.unmarshaller(Car.class), car -> {
                            return complete(car.getColor());
                        })
                    )
                )
            )
        )