Answer the question
In order to leave comments, you need to log in
Architectural question on Web API. How to properly share a token between instances?
Greetings.
I have very little experience in these matters, so I decided to turn to knowledgeable people so that later it would not be excruciatingly painful. I am writing a modest client for WP for one site using a self-written API. I started everything from a draft version, but then it went off and on and it grew to an indigestible size. At the moment, to use the API, I create 1 global instance of the class of this API, authenticate through it, and it stores the token in itself. Then I simply pull the methods of this instance, for example:
myapi.LikeRecord(Record rec);
Accordingly, the method inside lacks a token and LikeCompleted passes through the output.
I would like it to look a little different for me: I want to make Record more independent and use
Recrod.Like();
but how to properly organize token sharing in this case? Only some kind of static class comes to mind, but what if this is not the right direction?
Prompt at least in what direction to me to dig.
Thank you very much!
Answer the question
In order to leave comments, you need to log in
Leave as is. Record.Like() is a clear violation of SRP . Plus, an extra headache about "how can I create an object of the Record class" - and there it is not far from factories with decorators and other enterprises.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question