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

RESTful behaviour #2122

Closed
psuplat opened this issue Aug 10, 2019 · 2 comments
Closed

RESTful behaviour #2122

psuplat opened this issue Aug 10, 2019 · 2 comments

Comments

@psuplat
Copy link

psuplat commented Aug 10, 2019

First of all I apologize for throwing a "help me" question here instead of on the forum, but since the registration is temporarily disabled I can't create an account to post.

I trying to understand how the HTTP verbs in routes function.

I have a route defined as such:
$routes->post('/users/create', 'Users::create');

and my controller is as follows:

<?php namespace App\Controllers;

use App\Models\UsersModel;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\Request;

class Users extends BaseController
{
    use ResponseTrait;
    
    
	public function create()
	{
            // Some code in here
            return $this->respond($data, 200);
        }
}

now, if I try to access the route with GET method I would expect to see some kind of error, probably 405 - Method not allowed. Instead the code executes and I get a 200 response.

Am I missing something obvious here?

@MGatner
Copy link
Member

MGatner commented Aug 10, 2019

If you didn’t turn off autorouting then users/create will still match to Users::create without any explicit routes.

@jim-parry
Copy link
Contributor

$routes->post('/users/create', 'Users::create'); will add a route.
Any "get" route that would resolve normally still will, so your "200" is expected.
You can ask questions on the slack channel until the forum registration has been restored.

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

3 participants