Aggregation of data on API Gateway - microservices

I am working on microservice architecture and I want to aggregate data from two microservices.
For example, Frontend calls the API Gateway and API Gateway calls two microservices Customer and Order microservices. Customer microservice returns customer details and Order microservice returns all ordered products by customer.
This is the format returned by API Gateway after aggregation from two microservice using Ocelot or Azure API Management.
Format 1
{
"Customers":[
{
"customerId":1001,
"customerName":"Tom"
},
{
"customerId":1002,
"customerName":"Jerry"
}
],
"Orders":[
{
"CustomerId":1001,
"Orders":[
{
"ProductId":"PRO1",
"ProductName":"Books"
},
{
"ProductId":"PRO2",
"ProductName":"Pens"
}
]
},
{
"CustomerId":1002,
"Orders":[
{
"ProductId":"PRO3",
"ProductName":"Pencils"
},
{
"ProductId":"PRO4",
"ProductName":"Toys"
}
]
}
]
}
The Format that I want is format 2.
Format 2
{
"OrderDetails":[
{
"customerId":1001,
"customerName":"Tom",
"Orders":[
{
"ProductId":"PRO1",
"ProductName":"Books"
},
{
"ProductId":"PRO2",
"ProductName":"Pens"
}
]
},
{
"customerId":1002,
"customerName":"Jerry",
"Orders":[
{
"ProductId":"PRO3",
"ProductName":"Pencils"
},
{
"ProductId":"PRO4",
"ProductName":"Toys"
}
]
}
]
}
The second format is achievable using Ocelot but the merging of data is based on the ids on Gateway and it requires some processing.
Is it a good practice to aggregate data on Gateway using business logic. If not what practices should be followed for this kind of aggregation?
It would be nice if you can provide some references for achieving this aggregation using the Azure API Management.

This is known as API composition or Backend for Frontend. I would say it is fine to aggregate data using the API Gateway because it allows your API clients to use a simpler API interface. The actual mapping would be done in the API Gateway.
However, when you chain multiple microservices together in one Web API, the failure of one service will cause the entire Web API to fail. An alternative (and more complex) solution is to create a dedicated microservice that aggregates the datasets from the other microservices and expose a single API that shows the joined data. See - CQRS pattern.
A reference for how you might implement this in Azure is API Aggregation Using Azure API Management.

Related

Auditing in spring boot - How to custimise?

I followed this document for implementing Auditing in spring boot.
(https://www.baeldung.com/database-auditing-jpa)
Auditing is working fine but when the object is of type list means we are persisting as multiple entries in db.
I am passing this request object for rest API :-
`
[
{
"name": "reddy"
},
{
"name": "mani"
}
]
`
for each object we are getting one audit log in db.
Is there any way to achieve as single entry in database?

Google Form Api. Adding Response validation to textQuestion

Currently, AFAIK, when performing google form batchUpdate using the google forms API v1, we are only able to set the shuffle property of choiceQuestions, while for textQuestions there are no options to set the response validations, like if I want to use regex match as validation.
For Example, the request body looks like this:
{
"requests": [
{
"createItem": {
"item": {
"questionItem": {
"question": {
"choiceQuestion": {
"shuffle": false
},
"textQuestion": {
"paragraph": false
/*no other parameters to set*/
}
}
}
}
}
}
]
}
Am I missing something? Or is this feature not implemented yet?
You are correct, this has not been implemented yet. For now, these are the only options that can be used with ChoiceQuestion This is kind of expected taking into consideration FORMS API was launched just last month.
So you may want to submit a Feature Request for that missing feature.
In the meantime, you can also consider tackling this using Google Apps Script and its Forms Advanced Service which includes response validation.

Is it possible to set several routing values using Elasticsearch NEST?

I need to query data from several shards. Elasticsearch REST API provides a possibility to send a request with several routing keys:
//https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html#_searching_with_custom_routing
GET my-index-000001/_search?routing=user1,user2
{
"query": {
"match": {
"title": "document"
}
}
}
Is it possible to do the same by NEST client?
Yes, you can pass a comma-separated string to the Routing() method of a search request.

Google Plus Domains Api Activities: insert 403 Forbidden

I try to use insert activity request through this special form http://joxi.net/J2bykQQS4XYxXm
{
"object": {
"originalContent": "LaLALaLALa"
},
"access": {
"items": [
{
"type": "domain"
}
],
"domainRestricted": true
}
}
but always I have 403 error in answer. http://joxi.net/DrllG33c4vnb5r
I tried to use user_id instead me but had same results :(
Most likely, you are not doing this as part of a Google Domain. Now also known as "gsuite", this allows companies to be able to post messages that are visible to other members of the same company. This does not allow you to post messages that are available for most Google+ users to see.
There is no public API available from Google to let you post to the public Google+. There is an API available to select partners (such as HootSuite) which let them post to the public Google+, but they seem to be slow or reluctant to add additional partners.

ServiceNow REST API: return single column

Is there a way to perform a REST call to ServiceNow REST API that returns a single column of a table? I would like to query the server table for only the names of the servers and not have the entire record containing some 50 plus fields returned.
The latest REST Table API (as of Eureka, I think) supports the parameter sysparm_fields, which allows you to specify a comma-delimited list of fields to include in the response:
This URL template:
https://YOURINSTANCENAME.service-now.com/api/now/v1/table/incident?sysparm_fields=number,short_description,caller_id.name
Would give you a result with something like:
{
"result": [
{
"caller_id.name": "",
"short_description": "Unable to get to network file shares",
"number": "INC0000002"
}
]
}

Resources