Reputation: 1244
I'm trying to find out the best approach for designing the following scenarios.
Let's assume, that I already have, a REST API
implementation, which is going to fetch books, from different providers and serve them back, to my own client.
API
for serving books to its consumers.Some output examples:
Provider 1
[
{
"bookId": 32,
"bookName": "foo",
"author" : {
"name" : "John",
"surname": "Doe"
},
"publisher": {
"name" : "Foo Books",
"address": "New York"
}
},
...
]
Provider 2
[
{
"publisherCompany": {
"name": "Foo Books",
"position": "New York",
"books": [
{
"id": 32,
"title": "Foo",
"author": {
"name" : "John",
"lastName": "Doe"
}
},
...
]
}
},
...
]
Both of those 2 providers, are outputting the same values, but in different format. Moreover some keys are completely different.
What I'm looking for, is an Architectural Design or a Design Pattern, so i can map each different output, to my own format.
What i have tried in the past
My questions:
Design Pattern
for this?Thanks ;)
Upvotes: 3
Views: 2708
Reputation: 17460
Not everything must follow a design pattern or have a name, just use your knowledge and common sense.
In this case, what you want is the following:
Both Services related to Provider 1 and 2 should implement the same Interface that specifies the contract for additional Provider Services that you might need. This would be the Interface that your domain Service layer would know and use.
This is more or less what you already have but if you want to give this a name, you can read about Hexagonal Architecture which has some similarities with the described solution. I suggest the following articles:
Upvotes: 2