Giter Site home page Giter Site logo

Why isn't broker a handler? about broker HOT 6 CLOSED

northwoods avatar northwoods commented on August 29, 2024
Why isn't broker a handler?

from broker.

Comments (6)

shadowhand avatar shadowhand commented on August 29, 2024 1

@XedinUnknown this is fixed in version 3.0.0, see #13.

from broker.

XedinUnknown avatar XedinUnknown commented on August 29, 2024

It appears that there is in fact a separate handler implementation that does this, which is not apparent from the readme. Still, given that this handler implementation is not what the consumer of Broker will interact with, it seems more natural for Broker itself to be a handler.

from broker.

shadowhand avatar shadowhand commented on August 29, 2024

Broker can already be used as a handler, it just needs a callable $default to generate a response when none is generated by a middleware.

from broker.

XedinUnknown avatar XedinUnknown commented on August 29, 2024

If broker could be used as a handler, then I could use it in a method that accepts RequestHandlerInterface, and in the exact same way. But Broker does not implement RequestHandlerInterface (both formally, and because its handle() method requires a second parameter), and therefore cannot be used as a PSR-15 handler. Sorry if it was not clear that I am referring to formal PSR definitions, not simply usage.

from broker.

shadowhand avatar shadowhand commented on August 29, 2024

@XedinUnknown what would the benefit of that be? I tried implementing RequestHandlerInterface and it didn't really seem to offer any value. Broker doesn't know what response should be given when it no longer has middleware to process, so all it can do is generate an empty HTTP 500.

from broker.

XedinUnknown avatar XedinUnknown commented on August 29, 2024

Sorry, perhaps I wasn't clear from the beginning.

The consumers of Broker will most likely use it as an entry point to the application. They will probably marshal some environment values, such as those coming from a SAPI, into a server request object, give it to Broker, and emit the response. So, Broker is the main handler of the request, and therefore conceptually it looks more like a handler: they would want to "handle" the request in some familiar and interoperable way. Whereas if it is a middleware, they would have to have a stack implementation, and a handler, and a router/dispatcher. But Broker is already all that, so it looks more like a handler to me from this point too.

I must admit that, although the concept of a middleware pipe in general (as opposed to HTTP specific middleware) was something that I had separately come up with a few years ago, I'm finding it hard to understand the separation between Middleware and Handler. Middleware is usually dispatched as part of a stack; each middleware can be capable of producing a response; and it should have the ability to "forward" the request to the next middleware somehow. So, not sure how the concept of "handler", especially as a second parameter to process(), fits into the middleware paradigm. That said, you don't directly dispatch a middleware or a stack, and to be conceptually correct there needs to be a "handler" that simply gets a request and produces a response, without exposing detail of how that happens (perhaps via a middleware stack). This is especially confusing given that there doesn't appear to be consensus on how exactly middleware stacks are dispatched, and what is their relation to middleware. Some handlers dispatch stacks, others produce a response, some do both, and some do more than that. But I prefer to operate within a field of concepts, rather than standards or implementations, and IMO the current docs on the standard don't really give a clear description of this.

from broker.

Related Issues (4)

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.