For a long time, I’ve been using Repository pattern to abstract data access logic from actual business logic, always using SQL or noSQL databases as my data source.
But how much valid is it, to abstract data access logic into repository, if our data source is a 3rd party REST api?
Is there any other better architectural approach for this?
(For my particular instance, I am developing a REST API to automate things on that 3rd party platform, and obviously I would need to do the CRUD operations to the data through that 3rd party REST API.)
-
2If you are performing operations on a SQL database or a Redis instance, then you are calling out to a 3rd-party API. There's absolutely no conceptual difference between this and calling a REST API, the only difference is in the implementation detail, which a repository is intended to abstract away.Ben Cottrell– Ben Cottrell2025年01月19日 23:45:30 +00:00Commented Jan 19 at 23:45
-
1Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.Community– Community Bot2025年01月20日 01:10:20 +00:00Commented Jan 20 at 1:10
-
From the perspective of your application and its codebase; what is the meaningful distinction you seem to be making between an external database (hosted on a server) and an external service (hosted on a server)?Flater– Flater2025年01月21日 02:40:11 +00:00Commented Jan 21 at 2:40
1 Answer 1
my data source is a 3rd party API
The difference between a Repository and a Client is really just the methods that they make available.
For you to use the third party API as a Repository, it would have to offer CRUD style methods. Since you can't control what methods are offered, and assuming there is a mix, then its really down to semantics what you call your interfacing code.
-
Agreed. I've always thought of a "repository" and a kind of service; one that specializes in data access.Greg Burghardt– Greg Burghardt2025年01月20日 01:42:07 +00:00Commented Jan 20 at 1:42
-
Thanks for the answer! what would be most applicable semantics in your opinion?Hexley21– Hexley212025年01月20日 11:17:47 +00:00Commented Jan 20 at 11:17
-
-
1The semantic distinction that I often run with is that a repository is bidirectional (i.e. the data reposes there inbetween us putting it there and us fetching it again), whereas as provider is onedirectional (we fetch data from it, we do not put it in there ourselves). But this is a semantics argument, not a technical one.Flater– Flater2025年01月21日 02:42:08 +00:00Commented Jan 21 at 2:42
Explore related questions
See similar questions with these tags.