❔ Architecture when using external API
Howdy,
I got an application, and it's going to make a call to an external API, get back a response. Take that response and transform it to the models I use for my application. Pretty straight forward stuff.
Worth noting, my Application is 3 layers, the main Application Layer a WebApi project, a domain layer with all my models and such, and the data layer for all my data needs.
My issue comes from the fact that the response the external API provides is this massive object with a lot of nested objects etc. And I don't really like that it can leak into other things.
I'm not sure if it's better to break it out into it's own class library, sort of putting it on an island so it's probably gonna stay isolated.
Or if it's better to go in and rename all the classes in the response model to sort of "tag" them with the API it's calling, so that they're distinct and not leaky?
With Leaky I mean that I have a "Comic" class for my application, but this response object also wants to have a "Comic" class so it gets gross. But I could name the response like ApiComic or whatever?
What is a good way to deal with this?
5 Replies
The types for the API response should be in a dedicated namespace, and that should solve all your issues
so
Comic
from the API would be ProjectName.ApiName.Comic
when fully qualified
and then you just don't import that namespace outside of the serialization/mapping logic and you're good to goah yeah that do be making more sense, thank you very much!
also, remember that for json serialization, you dont need to specify every single prop
partial serialization is supported 🙂
so if the JSON is massive, but you only care about 2-3 fields per object, you can provide only those fields
Yeah what I've done is copied the response and used the paste as classes haha 😛 if I in the future care about more than I do now I can add them in and it will map over
But I probably could clean out
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.