1

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.)

asked Jan 19 at 23:35
3
  • 2
    If 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. Commented Jan 19 at 23:45
  • 1
    Please 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. Commented 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)? Commented Jan 21 at 2:40

1 Answer 1

2

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.

answered Jan 20 at 0:03
4
  • Agreed. I've always thought of a "repository" and a kind of service; one that specializes in data access. Commented Jan 20 at 1:42
  • Thanks for the answer! what would be most applicable semantics in your opinion? Commented Jan 20 at 11:17
  • list the methods on the api? Commented Jan 20 at 11:34
  • 1
    The 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. Commented Jan 21 at 2:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.