• Resolved crea8xion

    (@eyouthace)


    hi,

    I had a problem with registering a custom route from the docs

    http://example.com/wp-json/myplugin/v2/author/id=1
    register_rest_route(‘myplugin/v2′,’/author/(?P<id>[\d]+)’, array(
    ‘methods’ => ‘GET’,
    ‘callback’ => array($this, ‘my_awesome_func’),
    ‘args’ => array(
    ‘id’ => array(
    ‘validate_callback’ => ‘is_numeric’
    ),
    ),
    ) );

    it returns

    {
    “code”: “rest_no_route”,
    “message”: “No route was found matching the URL and request method”,
    “data”: {
    “status”: 404
    }
    }

    while doing so

    http://example.com/wp-json/myplugin/v2/author/
    register_rest_route(‘myplugin/v2′,’/author’, ….)

    returns

    “Testing from post type post”

    May i know whats causing it?

    WP 4.3.1
    wp-rest-api Version 2.0-beta7

    https://ww.wp.xz.cn/plugins/rest-api/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Your request needs to be:

    http://example.com/wp-json/myplugin/v2/author/1

    Note: I’ve dropped id= from the path.

    Thread Starter crea8xion

    (@eyouthace)

    ok

    Can I make a custom route that accepts arguments for inserting values to a custom table?

    e.g.

    register_rest_route( $this->namespace . $this->version, ‘/’ . $this->base . ‘/(?P<gcmid>[\d]+)’, array(
    array(
    ‘methods’ => WP_REST_Server::READABLE,
    ‘callback’ => array($this, ‘my_awesome_func’),
    ‘permission_callback’ => null,
    ‘args’ => array(
    ‘id’ => array(
    ),
    ),
    ),
    array(
    ‘methods’ => WP_REST_Server::CREATABLE,
    ‘callback’ => array( $this, ‘create_item’ ),
    ‘permission_callback’ => null,
    ‘args’ => array(
    ‘gcmid’ => array(
    ),
    ),
    ),
    ) );

    and the full route would be

    http://example.com/wp-json/myplugin/v2/gcm/gcmid=12345

    I still got 404…

    Thanks..

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Can I make a custom route that accepts arguments for inserting values to a custom table?

    Yes, it’s possible.

    and the full route would be

    Again, the route you’re specifying with your regex is different than the route you’re trying. With the regex pattern you’ve specified, the URL would be:

    http://example.com/wp-json/cigapi/v2/gcm/12345

    Note: I’ve removed gcmid= from the path.

    Thread Starter crea8xion

    (@eyouthace)

    Sorry,

    This is not 404, its working..

    This works
    http://example.com/wp-json/myplugin/v2/gcm/12345

    But returns me on [POST]

    “No response received”

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘register route 404’ is closed to new replies.