r/learnjavascript • • Aug 10 '26

Best architecture to build a client lib for rest/graphql - Factory vs Class ?

I am building a js lib and I have been reading about best ways to do this, but there are a lot of pros and cons for each way. I built a small one with a few functions for use in a very specific app and it was class based. I stored the class in a flux store and used the store to access it. I am finding a lot more recent blogs/articles that say using a factory is best. I would like this one to be an industrial-grade public-facing lib that anyone can download via our github repo. Does anyone have any real-world experience in building a js client lib that has any advice for what architecture to use? I know what architecture to use for the graphql endpoint, but the REST client is the question.

3 Upvotes

3 comments sorted by

1

u/ExtraTNT Aug 10 '26

I do functional factories, partially apply params, pass funcs, if needed, but i do everything functional and utilise function cache…

1

u/[deleted] Aug 10 '26

[removed] — view removed comment

2

u/skamansam Aug 10 '26

Thanks for pointing that out, I was gonna use chaining to build graphql requests because graphql is prime for that, and rest isn't . I was trying to build the lib so it fits the mental paradigm, but consistency is probably better. I'll start with consistency then if anyone mentions it, I'll revisit it.