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

New here, wanted to chip in with an idea #40

Open
Evertt opened this issue Dec 27, 2015 · 1 comment
Open

New here, wanted to chip in with an idea #40

Evertt opened this issue Dec 27, 2015 · 1 comment

Comments

@Evertt
Copy link

Evertt commented Dec 27, 2015

Hi guys,

I'm just learning Swift at the moment. I'm coming from PHP where I use the framework Laravel a lot and I'm trying to switch to swift because I find the language much more beautiful and because it can be much more performant. And now I found Taylor and I really like it.

Looking at the source-code of Taylor and specifically the way it uses handlers / middleware I felt inspired to mix your way of doing it with Laravel's way of doing it.

What if a handler looked like this:

{
    request, response, next in

        // I can do all kinds of things here, before I continue to the next middleware

        (request, response) = next(request, response)

        // Here I can do things that need to be handled on the way out,
        // after the controller has run so to speak

        return (request, response)
}

IMO, this is a bit cleaner than calling callback(.Continue(request, response)). Now you can choose between "continue" and "send", simply by choosing whether to call next or not.

And another nice thing about this, I read in #12 that you guys wanted a way to make sure if "Continue" was called last, it would be automatically converted to "Send". Well in this case, that is trivial. All you need to do is add a dummy handler at the end that does nothing but return the request and response immediately.

This way of doing it implied that request and response are value types, not classes, but I think one can just as easily use classes. In that case it would look like this:

{
    request, response, next in

        // I can do all kinds of things here, before I continue to the next middleware

        next(request, response)

        // Here I can do things that need to be handled on the way out,
        // after the controller has run so to speak
}

What do you guys think?

@Evertt
Copy link
Author

Evertt commented Dec 28, 2015

Check out this repo if you want to check out an implementation of my idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant