metodo para listar crud api fetch

<?php
    require_once "conexion.php";
    $consulta = $pdo->prepare("SELECT * FROM productos ORDER BY id DESC");
    $consulta->execute();
    $result = $consulta->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as $data) {
        echo "
            <tr>
                <td>" . $data['id'] . "</td>
                <td>" . $data['producto'] . "</td>
                <td>" . $data['precio'] . "</td>
                <td>" . $data['cantidad'] . "</td>
                <td>
                    <button type='button' id='editar' class='btn btn-success' onclick=editar('" . $data['id'] . "')><i class='fas fa-edit'></i></button>
                    <button type='button' id='eliminar' class='btn btn-danger'><i class='fas fa-trash-alt' onclick=eliminar('" . $data['id'] . "')></i></button>
                </td>
            </tr>
        ";
    }
    
?>