Im currently working on a little side project where I want to query an api via cloud functions.
The API has several endpoints, say "Users" and "Posts".
Do I create one function for each endpoint? ie:
getUser(id) => Userdata
getPost(id) => Postdata
OR do I create one single function that chooses the endpoint via a given paramenter:
getApiData("user", id) => Userdata
getApiData("post", id) => Postdata
Are there any best practices? What are the pros and cons? How do you do it?
Architecturally I don't believe there is a best practice with Cloud Functions specifically. Your idea of injecting the endpoint makes it flexible for any future APIs you have, and would follow the SOLID design principles.
You could send an object with all necessary data and only have one function, using a library like request. Then all you have to do is structure your input parameters to match.
Something like this: