How do I maintain API versions? I have different REST End points in my Drupal 8 instance, some of them are exposed from REST Views and some are custom controllers. I have a situation where I want to maintain versioning with my end points.
I have replaced some fields in the new version and the users relying on the older API version must not be impacted by the change.
In the case of a controller, how can I manage different output for different API versions?
Also, in the case of REST Views, where the URL is directly exposed, how can new data be added to that?
For example, the /rest/taxonomy-list endpoint gives a certain set of terms as JSON output. In the new API version, I have to add/remove/replace one term which is present in same vocabulary.
One approach to version the API is to add a version number to the URL.
So, for example your Views REST display URL /rest/taxonomy-list would become /rest/v1/taxonomy-list or /rest/v2/taxonomy-list
You could duplicate the existing Views display to adjust the fields and new URL in a new REST display.
For custom REST API plugins, you can extend the existing RestResource and give it a new URL, e.g:
use Drupal\my_module\MyRestResource;

/**
 * Sample Rest Resource
 *
 * @RestResource(
 *   id = “my_rest_resource_v2”,
 *   label = @Translation(“My Rest Resource (v2)“),
 *   uri_paths = {
 *     &quot;canonical&quot; = &quot;/api/rest/v2/endpoint”
 *   }
 * )
 */
class MyRestResourceV2 extends MyRestResource {

  // Extend and override functions here 

}