4 ms·
I haven't used an online service for this, but I write a lot of server APIs for mobile games. It helps to think of the server call as "just an async function th
by xsmasher 4y ago
I haven't used an online service for this, but I write a lot of server APIs for mobile games. It helps to think of the server call as "just an async function that takes type A and returns type B." Your client's ServerConnection is just a class that implements all of those functions.
You can easily write a version of ServerConnection that returns local data instead of making network calls, and then later replace it with the real version that talks to the server.
If your backend is written in the same language, you now have the blueprint for the backend service too; you know exactly what methods it has to implement. You just need some boilerplate around it to turn JSON -> type A -> run f(A) -> type B -> return JSON.
If you're using a different language it would be nicer to have the API defined in a language-agnostic way; it's always possible to create that language-agnostic spec from your code that defines the interface/types.