• I’m building an app which uses data from a WordPress backend. Most of the data is cached in JSON files on the server, but the app allows comments to be placed, so the API has to be called from within the app. I’m worried that when WordPress decides to change the URL from /wp-json/wp/v2/ to /wp-json/wp/v3/ I have to update the apps that use the URL. That is why I was hoping to rewrite this URL to something more generic like /api/.

    Is this possible? My first attempt failed and simply shows the index.php from the theme directory:

    RewriteRule ^api/(.*)$ /wp-json/wp/v2/$1 [NC,L]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello @vespino,

    Just add the following filter to your functions page to change the API base. The below will change the REST api route from example.com/wp-json/wp/v2/ to example.com/api/wp/v2/.

    I don’t think changing the namespace is good idea!!.

    add_filter( ‘rest_url_prefix’, ‘my_theme_api_slug’);
    function my_theme_api_slug( $slug ) {
    return ‘api’;

    }

    Thread Starter vespino

    (@vespino)

    That is something I already found but does not quite solve the issue, does it? If the guys at WordPress decide to change /v2 to /v3 I still have the same problem.

    There is something called register_rest_route to create custom API routes. I don’t have much idea about.

    Does this logic work for you

    Inside app – > fetch the value of comment API dynamically

    For example read a text file over url which has the comment API URL mentioned. Even if the comment url changes in the future, you can simply change the URL in the text file the same will be reflected in the app coding?

    Does it work for you?

    Thread Starter vespino

    (@vespino)

    That would work, but only as a final resort since I believe this creates unnecessary traffic to the server and certain values must be set on the server.

    I’m not an expert developer. But, my logic says that there should be a file which will check by the app every time and should work based on the data on the file.

    For example: The remote file should have a variable named Force_update: this value either be yes or no. If in case you find any major bug in your previous app release, you can just refer it as yes and can force the users to update the app.

    I’m not sure whether any other option available inside android development toolkit to deal with such issues!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘custom url’ is closed to new replies.