I am stuck in a scenario wondering about the best practice that can be applied for that. I am working on an Ecommerce website dealing in orders, shipments, invoices etc.
Apart from UI creation in my application i also have the ability to send/receive data from different suppliers(through supplier apis xml/json). The application can post orders/shipments to a supplier created in my application or get all orders/shipments from a supplier to import in my app. The scenario varies from supplier to supplier.
My question is what would be the best approach to handle this. Below are the two approaches i have thought of. I am using the first approach right now but i am thinking whether its the right one to be used in this case.
1.) I have created a generic code to generate JSON/XML based on XPATH. For example for below XML generation i use the XPATH as Orders.order.orderNumber
<Orders><order><orderNumber>testorder</orderNumber></order></Orders>
The XPATH is stored in database and based on the different configured XPATH in database, complete JSON/XML is generated and sent to the supplier(GET/POST is also configured in database).
The advantage i think of this approach is minimal work to add new suppliers into the system. The disadvantage i think it has is the XML/JSON generation which goes through big loops. As the API's to be called for suppliers(Orders GET etc) are mostly fixed, this appears to be a disdvantage.
2.) I create separate services to handle each supplier calls, create methods that handle each call with XML hardcoded into the application(Without configuration in DB through XPATH). For ex, for 2 suppliers SuppA and SuppB. For SuppA orders list is to be downloaded and for SuppB shipments are to be posted. So there will be 2 services in my application handling each supplier calls independent of one another, 1 for SuppA and another for SuppB. SuppA service will call the orders GET api and SuppB service will call Shipments POST api.
The advantage of this i think is that it would be fast as XML/JSON generation would not be needed as only the required calls will be coded in the service codes for each supplier. The disadvantage i think it has is that only fixed services can be called. I the first approach anything could be changed through DB, but in this code needs to be changed.
Please suggest on this. Which approach is best for this scenario, the Generic DB configuration or the hardcoded separate supplier services?