The short version of my question is that I'm trying to wrap my head around how models are "shared" between an API Gateway and internal microservices. I assume that the gateway can be responsible for transforming calls to multiple services and returning a new aggregated representation of the data. How does the gateway know about the available models from the microservices?
In my simple example. I have:
- API Gateway
- User Service
- Restaurant Service
User Service
This rest service would expose an /api/users endpoint
Model
{
"id": 12345,
"name": "Joe Bloggs",
"e-mail": "joe@bloggs.com",
"lastloggedin": "05/10/2017"
}
Restaurant Service
This rest service would expose an /api/dishes endpoint
Model
{
"dishes": [
{
"userId": 12345,
"isActive": true,
"type": "italian",
"sub-types": [
"pizza",
"pasta"
]
},
{
"userId": 12345,
"isActive": false,
"type": "american",
"sub-types": [
"burgers",
"steaks"
]
}
]
}
API Gateway
The API Gateway could allow for someone to call /api/user/12345/dishes or /api/dishes and it would return dishes for cooks. Along with some basic user details.
Model
{
"cook": "Joe Bloggs",
"lastloggedin": "05/10/2017",
"dishes": [
{
"type": "italian",
"sub-types": [
"pizza",
"pasta"
]
}
]
}
At this point. I've identified 3 models (i.e. C# classes). 2 from the internal services and 1 for the new representation of the data being returned from the API Gateway. I am unsure as to how the API Gateway knows about the User and Restaurant service models without coupling those models directly to the API Gateway as well. Essentially sharing code between the Gateway and the Microservices, which I believe is not desirable.