Use of batch in REST endpoints
Batch API operations are driven by the end user and browser with meta refresh, which makes it not possible to use in web services. However we can think about implementing the same thing using Queue API.

This should give you enough to go on to re-implement your RestResource or Controller to use your own Queue service.

Summary

I've used the following pattern in the past.


First request has a payload that can instantiate the operation.


It's important to make sure we're not flooding the serve so make sure you have flood protection.
Make sure that we have access to do the operation.

A response is returned with progress state and a queue item ID.
Subsequent requests have a payload with the queue item ID from the previous response.


These requests process 1..n queue items.
We need to claim queue items ourselves because we're processing queue items manually and not with a cron queue worker.
Make sure that things are valid and return the appropriate response code for validation, fatal or other errors.



Request payloads


Initial: {"queue": null}
Subsequent: {"queue": {"item_id": 1}}


Response payloads

Initial

{
   "success": true,
   "finished": false,
   "queue": {"item_id": 1},
   "progress": 0,
   "max": 23,
   "errors": [],
   "result": "something custom here",
}


Finished

{
   "success": true,
   "finished": true,
   "queue": null,
   "progress": 23,
   "max": 23,
   "errors": ["something wrong happened at some point"],
   "result": "something custom here",
}


Queue API

The complexity here is that we cannot use cron queue workers. So we need to implement the database calls to get and claim queue items ourselves. Unfortunately the current Queue API classes are pretty limited in both Drupal 7 and Drupal 8. In the former, I used custom functions to fetch and update queue items directly from the database while in the latter we can create our own service, based on DatabaseQueue, and inject that into your RestResource plugin or Controller.