Skip to content
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

Clarify: respondWithStatus #18626

Closed
ktoso opened this issue Oct 1, 2015 · 11 comments
Closed

Clarify: respondWithStatus #18626

ktoso opened this issue Oct 1, 2015 · 11 comments

Comments

@ktoso
Copy link
Member

ktoso commented Oct 1, 2015

Hi @sirthias @jrudolph,
I realised we don't have respondWithStatus ported to Akka HTTP.
On this one I'm not sure if it's an omission by design or accident, WDYT?

See:

Note to self ( remove // FIXME https://github.com/akka/akka/issues/18626 from code once resolved )

@ktoso ktoso added the 3 - in progress Someone is working on this ticket label Oct 1, 2015
@ktoso ktoso assigned ktoso and sirthias and unassigned ktoso Oct 1, 2015
@ktoso ktoso added this to the http-1.1 milestone Oct 1, 2015
@ktoso ktoso mentioned this issue Oct 1, 2015
59 tasks
@ktoso
Copy link
Member Author

ktoso commented Oct 1, 2015

PS: Sorry if I'm too noisy with all these "clarify" tickets – It's mostly so we're able to respond properly once people coming from spray start asking "hey, X is missing!", and I'm noticing those currently since documenting all directives.

I'm rather sure you made the right call when not porting something, just wanted to understand the reasoning behind it where it's not immediately clear to me 😄 Thanks in advance for the help!

@jrudolph
Copy link
Member

jrudolph commented Oct 1, 2015

I didn't remember we once had this directive and I cannot remember a reason for not having ported it or making any decision.

I think the main reason not to include it (despite seeming basic enough) would be that it isn't really useful in most cases. In most cases, you would first figure out the response status code before figuring out any other detail of the response, so the question would be why you would want to override it later on?

Common ways to specify the status code are:

  • use 200 OK ;)
  • use one of the marshallers that allows to specify a status code together with the entity body, e.g. as a Tuple statusCode -> entity
  • build a complete HttpResponsecompletely including the status code
  • reject a request and from a RejectionHandler return an HttpResponse including the (error) status code

I'm not against include responseWithStatus, but if it is included it should mention the more common ways of setting status codes.

@jrudolph
Copy link
Member

jrudolph commented Oct 1, 2015

And, no worries about the clarify tickets. They are easier to keep track of than reading through the chat and better for keeping the record for later questions, so 👍 for having them.

@sirthias
Copy link
Contributor

sirthias commented Oct 2, 2015

I agree with @jrudolph, keep the clarify tickets coming, Konrad! :)

As to respondWithStatus we did not port it simply for the reason that Johannes stated:
There is probably no good reason to use it.
Overriding the status code coming back from an inner route appears hacky to me. You can do it, if you must, but we shouldn't "bless" it by providing a nice shortcut.

@ktoso
Copy link
Member Author

ktoso commented Oct 8, 2015

For reference, we still have overrideStatusCode(201) which seems to do the same thing.

So we have it in that sense.
Strong enough opinions to remove it or keep as is, WDYT?

// cc @jrudolph @sirthias @rkuhn

@ktoso
Copy link
Member Author

ktoso commented Oct 8, 2015

At the very least made it not recommended:

  /**
   * Not recommended directive, try to solve your problem by providing a custom [[RejectionHandler]] for example.
   * 
   * Overrides the response status code with the given one.
   */
  def overrideStatusCode(responseStatus: StatusCode): Directive0 =
    mapResponse(_.copy(status = responseStatus))

@jrudolph
Copy link
Member

jrudolph commented Oct 8, 2015

Ah those elusive little directives, I guess we probably just renamed it during the migration and no one could remember...

Regarding the ScalaDoc maybe switch the lines around so that the summary is still at the top. That said, I wonder if we should keep it if we have only harsh words for it. Seems inconsequential and unfair to the little one. If we cannot find a positive description that would offer at least one however far-fetched use case for it, we should set it free.

@ktoso
Copy link
Member Author

ktoso commented Oct 8, 2015

Trying to be inventive I imagined this use case:

          authorize(quotaOk) {
            doThings()
          } ~
          overrideStatusCode(StatusCodes.EnhanceYourCalm) { // 420, e.g. used by Twitter
            doThings()
          } 

Not sure if that's realistic at all, rather not... 😉

@jrudolph
Copy link
Member

jrudolph commented Oct 8, 2015

It's still weird that you first build a full response just to get rid of it later on.

@ktoso
Copy link
Member Author

ktoso commented Oct 8, 2015

Ok, since we can't find a good use case, I'll remove it.

@ktoso ktoso assigned ktoso and unassigned sirthias Oct 8, 2015
@ktoso ktoso closed this as completed Oct 8, 2015
@ktoso ktoso removed the 3 - in progress Someone is working on this ticket label Oct 8, 2015
@ktoso
Copy link
Member Author

ktoso commented Oct 8, 2015

Removed, closing.

It's free now :-)

ktoso added a commit to ktoso/akka that referenced this issue Oct 8, 2015
we don't recommend using it.
ktoso added a commit to ktoso/akka that referenced this issue Oct 9, 2015
we don't recommend using it.
ktoso added a commit to ktoso/akka that referenced this issue Oct 12, 2015
we don't recommend using it.
ktoso added a commit to ktoso/akka that referenced this issue Jan 11, 2016
we don't recommend using it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants