Git Product home page Git Product logo

Comments (11)

ktoso avatar ktoso commented on August 26, 2024

Needs some checking with the spec IMO.
Not sure relativePath is correct, would be absolutePath right?
Perhaps require it should start with / (or protocol) then?

from akka-http.

aruediger avatar aruediger commented on August 26, 2024

We can add the matched path logic to RequestContext as requested in akka/akka#15839. What would be left is a simple respondWithHeader(Location(...)) which doesn't warrant its own directive IMO.

from akka-http.

aruediger avatar aruediger commented on August 26, 2024

FTR: Extracting the matched path is already implemented and hidden inside FileAndResourceDirectives#listDirectoryContents.

from akka-http.

rbudzko avatar rbudzko commented on August 26, 2024

@ktoso @2Beaucoup I could dance with this one, but it seems obsolete - based on akka/akka#15839. Can we establish if respondWithLocation is to be added?

from akka-http.

aruediger avatar aruediger commented on August 26, 2024

IMO: No. What do others think?

from akka-http.

jypma avatar jypma commented on August 26, 2024

Well my use case still exists: we want to send a server-root relative Location: back as part of a "POST to create resource" pattern, i.e.

POST /resources

201 Created
Location: /resources/42

without needing to repeat "/resources" in the routing logic.

from akka-http.

aruediger avatar aruediger commented on August 26, 2024

@jypma What do you think about #6 (comment)?

from akka-http.

jypma avatar jypma commented on August 26, 2024

You'd still need to combine two directives. Assuming ctx.getMatchedPath() returns Uri:

extractRequestContext(ctx ->
  respondWithHeader(Location.create(ctx.getMatchedPath().addPathSegment(myId)), () -> 
    complete(...)
  )
) 

It would reduce the custom code for sure, so it would be a definite improvement.

I'd personally still push it down into a respondWithLocation directive in my own code though... but if I'm the only one having this API style, it's obviously not much of a pattern :)

from akka-http.

jrudolph avatar jrudolph commented on August 26, 2024

I'm with @2Beaucoup on this one. Adding matchedPath to RequestContext (only necessary if we want to keep it as a field in RequestContext) or as a directive would be a definite win.

For which kind of responses do you want to add Location headers, @jypma? The redirection ones or 201 or something else?

from akka-http.

jypma avatar jypma commented on August 26, 2024

@jrudolph It's a 201 Created. Sorry, edited 2 comments ago to reflect that. So client POSTs a new resource to us, with the content in the body, server then makes up an identifier for that new resource, and returns its new location in the Location: header, which happens to always be directly underneath the URI that the original POST goes to.

Either way, just getting matchedPath would be an improvement, so by all means let's go forward with that. As long as Uri.addPathSegment would properly handle the current matchedPath ending or not ending in a slash.

from akka-http.

aruediger avatar aruediger commented on August 26, 2024

I added #496 to track the matched path feature. Let's close this for now.

from akka-http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.