Adding a computed value to an existing REST response avoids a round trip and keeps the field out of the post meta it was not really part of.
register_rest_field( 'product', 'in_stock', array(
'get_callback' => function ( array $post ): bool {
return turkerdev_stock_for( $post['id'] ) > 0;
},
'schema' => array( 'type' => 'boolean', 'context' => array( 'view' ) ),
) );
The callback runs once per item in a collection response, so a field doing a query turns a list endpoint into an N+1 — which is the reason to prime a cache in a rest_prepare filter or to accept that this field belongs on a separate endpoint. The schema is what makes the field appear in the OPTIONS response and in generated client code, and omitting it produces a field nothing knows about.