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

Route matching will 404 if not matching the method, even if the endpoint exists #50

Closed
Rican7 opened this issue Sep 10, 2012 · 3 comments

Comments

@Rican7
Copy link
Member

Rican7 commented Sep 10, 2012

Problem

If a route endpoint is matched, but the method used to get to the endpoint is not matched by a specified route, the router defaults to throwing a 404 error, which is not exactly what's happening.

Potential Resolution

Instead, too be more RESTful, we should let the developer/client know that the endpoint exists through a different method by sending back a 405 "Method Not Allowed" error.

Example

That way, when defining routes, we could simply do this:

<?php

respond( 'POST', '/user/profile/?', function( $request, $response, $app ) {
});

Without having to then do this for each route:

<?php

respond( '/user/profile/?', function( $request, $response, $app ) {
    if ( $request->method() != 'POST') {
        // Respond with 405
    }
});

As you can imagine, that would get pretty dirt over time with numerous routes or multiple methods per route.

@chriso
Copy link
Contributor

chriso commented Sep 24, 2012

I agree this is better than 404'ing. I haven't got time to refactor it at the moment but would gladly take a pull request

@Rican7
Copy link
Member Author

Rican7 commented Sep 24, 2012

Hmm. OK, I'll see what I can do.
The obvious challenge is adding the functionality while keeping the speed.

@Rican7
Copy link
Member Author

Rican7 commented Nov 14, 2012

Closing this issue, as you merged my changes from my Pull Request #56

@Rican7 Rican7 closed this as completed Nov 14, 2012
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

2 participants