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.
- Each provider offers a separate
API
for serving books to its consumers. - Each provider, has a completely different structure on the response from the previous one.
- My client should always get exactly the same format, so the frontend-client application can handle the responses.
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
- I had created my own Entities
- I had different services for each consumer and after fetching the data, i was instantiating my own entities and mapped the responses accordingly.
- After having my objects (Entities) filled with data, i was passing them to a transformer function to transform them to the desired output.
My questions:
- Is there any
Design Pattern
for this? - Is there any terminology for this scenario so i can do a research?
- In which way you would approach this scenario?
- Any resources for reading ?
Thanks ;)
Aucun commentaire:
Enregistrer un commentaire