I would suggest that the best alternative is to create your query as FetchXml and submit this query to the Web Api
<entity name=“account“>
<attribute name=“name“ />
<attribute name=“accountnumber“ />
<link-entity name=“contact“ from=“contactid“ to=“primarycontactid“ >
<attribute name=“emailaddress1“ />
</link-entity>
</entity>
</fetch>
I would suggest using the excellent Rest Builder to encode the FetchXML and generate the required JavaScript to call the Web Api endpoint