Working on api design where we need to expose endpoint to retrieve transaction data from azure cosmosdb through various queries. Taking an example of transaction data exist in azure cosmosdb. Below are the queries , api clients are expected to invoke request
Request1: Search Transaction By Trans_ID
Request2: Search Transaction By Phone_Number and Transaction_Item_ID
Request3: Request1 and Request 2
Request4: Search Transaction By CustomerID and Transaction_Item_ID
Design 1 : First approach is to expose a single api request which shall accomodate all the queries with the following pattern
POST /sales-transactions/search
{
"searchRequestId": "string",
"query": {
"phonenumber_itemid_filter": "phonenumber & itemid",
"transactionid_filter": "transactionid",
"partial_cardnumber_filter": "firstsix & last4"
},
"search_query_attributes": {
"itemid": [
"string"
],
"transactionid": [
"string"
],
"phonenumber": "string",
"firstsixcardno": "string",
"last4cardno": "string"
}
}
As you can see above client can request for multi query data in a single api request with the pattern above - You have query filter and query_filter_attribute data. When the controller receives the request with multiple queries , based on the query it will delegate each execution to its own query handler and then response of all query handlers will aggregated and sent back to the client
Issue with this design - based on query , need to pick appropriate handler which means use switch statements or reflection(perfomance issues)
Design 2:
Expose endpoints per each query
POST /sales-transactions/phonenumber_itemid_filter
POST /sales-transactions/partialcardnumber_filter
Using this design simplifies the implementation but when search requirement expands to more query/attributes ( pretty much the case) then we will keep adding more api endpoints.
Appreciate youR insights on best practices to be followed
Aucun commentaire:
Enregistrer un commentaire