-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract a header value or return default #639
Comments
Hi @zettelmj, thanks for the suggestion. I wonder if the new directive would be general enough to warrant adding it to the library of directives. Using (headerValue(headerName) | provide(default)) directly, instead, seems to be more explicit to me. |
Hi @jrudolph, that looks way better than what i tried over the weekend. Passing a function down through the directives makes all of the look very convoluted. Additionally it changes a bunch of signatures. Cheers |
Would you have some time to add this pattern to our documentation, in
That would be very nice of you :) A way of saying thanks in a way :-) |
I would say for the Java DSL is not that straight forward, unless #620 is done |
@jlprat agreed. |
@ktoso just putting it into headerValue feels a bit strange cause it is effectively just an application of http://doc.akka.io/docs/akka-http/current/scala/http/routing-dsl/directives/index.html#composing-directives. There are some examples in composing-directives but they aren't covering this scenario. Thank you |
Page with patterns would also be good, but this one I think is basically a headerValue "or else..." which is why I think it makes sense to add to its page. We have examples of directives which have such additional documentation (simply as section inside their docs) :) |
…e used to return the header or if the header is not present use a default (#666)
Issue: akka#639 Java example on how to provide a default value for a header extractor using directive composition
I some situation it would be handy to for the headerValue* directives to allow to specify a default value that is used if the header is not present.
for headerValueByName this could look like this:
def headerValueByName(headerName: String, default: String): Directive1[String] = headerValue(optionalValue(headerName.toLowerCase)) | provide(default)
The text was updated successfully, but these errors were encountered: