1

I have created a plugin for wordpress but I don't understand what an "arbitrary URL" is. Here's what I've found:

When installed, the plugin has to make a custom endpoint available on the site of WordPress. By "custom endpoint" we refer to an arbitrary URL not recognized by WP as a Standard URL, like a permalink or so. Please note that this is not a point of REST connection. When a visitor navigates to that endpoint, the plugin has to send a request HTTP to a REST API endpoint. The API is available at https: // jsonplaceholder. typicode.com/ and the connection point you are going to to call is / users. The plugin will parse the JSON response and use it to create and display a table HTML.

I would like you to tell me what this arbitrary URL is and clarify the question in general please.

1 Answer 1

0

Arbitrary by definition is:

Based on random choice or personal whim, rather than any reason or system.

WordPress sometimes generates URLs automatically and systemically. For example, whenever you create a new WordPress page it will, by default simply generate a URL based on the slug of the page title.

example.com/my-page-title/

We can change this but by default whenever we create a new page we can expect it to create that URL, remember that URL, and be able to pull data based on that URL.

An endpoint is something we know based on our needs. If a client needs an endpoint for computers for whatever reason, WordPress doesn't know this by default but we can tell WordPress to create an endpoint to recognize computers. We can create a custom REST endpoint by following The WordPress Handbook.

<?php
add_action( 'rest_api_init', function () {
    register_rest_route( 'myplugin/v1', '/author/(?P<id>\d+)', array(
        'methods' => 'GET',
        'callback' => 'my_awesome_func',
    ) );
} );

Following the link above, in their example they are creating a custom endpoint for their plugin that returns author posts. Again, the Endpoint is arbitrary, /author/ could be /computers/ if it makes sense based on our needs or the needs of the project. We would still need to build the functionality around the Endpoint but that is all covered in the linked Handbook above.

In any case, not every plugin is going to have or need their own Custom Endpoint or Custom REST Endpoints.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.