At the moment I have a frontend client calling several backend REST APIs. For example a call may be to get information about a certain vehicle. Then the client will call REST API A to get some performance data for the vehicle and REST API B to get some model or other static data.

This is becoming tedious to handle in the frontend client, so I'm currently building a BFF which can call these different APIs and aggregate them depending on the type of call from the client.

The problem I'm having is that in order to deserialize a json response from the APIs I need to deserialize them using a model that I have created in my project to map to the fields I get from each backend. Then I take the multiple deserialized objects from different APIs and create a new model that I then serve to the client and which may only makes sense for that client.

How do I separate these two types of models? Right now I have the API models in a Models folder and the client specific models in a ViewModels folder but I don't like the ViewModel name as I'm not really doing MVC.

There is no database so the BFF doesn't really own any entities/models. In general just having doubts on how to structure this project.

Edit: There is a hard requirement that .NET must be used so I'm doing the BFF in Web Api.

  • Have you considered to implement the mashup (BFF) with a progamming language with native supports for JSON notation? Lets say NodeJS. With such a language there's no need for (de)serialization. We don't even need to hard type aggregates or DTO, just concat and mix-up Jsons. We don't even need to synch calls to the backend
    – Laiv
    Feb 10 '19 at 19:31
  • I should have put that in the question but there is a hard requirement on using .NET as nothing else can be deployed in the environments. So I'm using Asp.Net Web Api (not core). But yes I see the huge advantage in using NodeJS in this case
    – Force444
    Feb 10 '19 at 19:33
  • Ok. Then, use Toleran Readers on the BBF. Avoid hard typing aggregates otherwise you couple the BBF with all the backends. Instead of DTOs, you could use Json libs. Those that use to allow us to read Json obj as Maps and do support JsonPath notation.
    – Laiv
    Feb 10 '19 at 19:37
  • @Laiv Thank you. That's also one the things I was worried about - if one of the APIs add a field to their model then the BFF breaks so using Tolerant Readers seems like a really good idea.
    – Force444
    Feb 10 '19 at 19:52
  • The thing around tolerant readers is that we can serialise without having to duplicate a whole remote web API data model. The coupling is reduced almost to nothing. But there's still coupling. Changing remote serivces' data models still force us to review the BFF, but with lesser costs.
    – Laiv
    Feb 10 '19 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.