I want to use the Steam WEB API to generate some stats about games. In order to use the Steam WEB API I have to use a key that I am supposed to hide. I want to do all of the data processing with JavaScript, which doesn't allow me to hide the key. So I came up with this solution. I query the database in php, and pass the JSON object to JavaScript. My question is whether or not this is the preferred or best way to do this.
PHP:
<?php
$matchDetailsUrl = "https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/? match_id=<MATCHID>&key=<KEY>";
$matchDetailsRaw = file_get_contents($matchDetailsUrl);
$matchDetailsJson = json_decode($matchDetailsRaw);
?>
JavaScript:
<script>
var obj = JSON.parse('<?php echo json_encode($matchDetailsJson) ?>');
console.log(obj);
</script>