Add ACF Meta to WP REST API Response

WordPress has a hook that you can use to interject a rest call before it is sent. You can use a function like the following (adapted from the SO answer linked in the resources) to add the ACF meta data into the response from the WP REST /posts API.

<?php
if ( ! function_exists( 'add_acf_meta_to_posts' ) ) {
    function add_acf_meta_to_posts($response, $post, $request) {
        
        // Return right away if no ACF found
        if ( ! function_exists( 'get_fields' ) ) return $response;

        // If the post is set then add our ACF meta to the ['acf'] field in the response for this post
        if ( isset( $post ) ) {
            $acf                   = get_fields( $post->id );
            $response->data['acf'] = $acf;
        }

        return $response;
    }
    add_filter( 'rest_prepare_post', 'add_acf_meta_to_posts', 10, 3 );
}