How is there a difference here between "code APIs" and "rest APIs"? Both are simply interfaces which allow two pieces of code to talk to each other, the only difference is the protocol used (HTTP vs the platform's ABI)
Because copyright law doesn't care just about the purpose of a creative work, but also about its precise form and medium of expression. Why? That's a whole other discussion.