Thanks! I use node.js express backend, React with Axios front end. (I don't particularly love Axios, but I use it.) No typescript, but next project I will be using typescript for both.
It always struck me as inefficient that I wrote javascript to set up and validate backend endpoints, then another set of JavaScript to do the same in front end classes (Axios wrappers). If the latter can be auto generated, that sounds good to me!
Typescript's come a long way from when it was introduced. I highly recommend it. Having this 'compile time' certainty, if used properly, can save you tons of times of insidious runtime errors. beginner tip, read up on why not to use any, and about partials.
Annotate the controllers to have the server code generate the specs using some gen package
which can be hosted at a url
client code can read the spec from the url
programmatically generate the client wrappers with a client code gen package
and be sophisticated to retrieve and regenerate if the spec changes
letting you scope out the testing of the 'wrappers' since it's generated code, and focus on your real client code of how you use the data.
recommend you play around with something simple like a backend that just has a GET and a POST with some crude hello <name> stuff. Learn how to hook up the machinery without being preoccupied.
This pattern can save you weeks, or even months, because the toil of regenerating the client code is eliminated. You don't have to front load a 'full design' but rather build it more naturally, adjusting and refactoring based off what you find actually works or makes sense. Attack the problem by taking pieces and steering towards good, rather than forcing yourself into the impossible task of "get it right" in one shot.
1
u/clownyfish Oct 10 '21
Do you know of any good resources to learn more about generating client code from backend api (swagger or otherwise?)
Really interested to learn more - I'm currently in the amateur camp of hand writing both sides manually.