user2062455
user2062455

Reputation: 421

one query from multiple APIs

Is it possible to make one query from API's from different sources? ie,

In traditional web development If I have the following modules:

I would create 2 tables in ONE database and foreign keys with joins and make my query.

What I would like to do is instead of ONE database to create 2 databases, one for each module (this way I can expand each module as it's own entity easier) and "tie" the 2 databases through APIs.

So, I would still use "foreign keys" (ie, clientID in the Orders table) to "tie" clients and orders, but I could not "join" them because they are not in the same database.

So, in my interface I would have a:

How would I do a query (or is it possible) though APIs between the modules to get this response:

I could show all Orders(http://mysite.com/showSalesAPI) that have clientID=1 but that would give me a json response with the clientID and not the clientName.

Does that make sense?

(you might ask why I would want to do this. this is part of a multi module application that it would make sense to keep the modules separate than as part of a huge database, for future development or interaction with other applications)

Any thoughts?

Upvotes: 1

Views: 363

Answers (1)

ryan1234
ryan1234

Reputation: 7275

I like the idea of splitting out databases and putting them behind services, but I think it should be done with care. If you are going to do joins constantly between clients and orders, why make them communicate via services?

Some thoughts:

  • Maybe replicate data from server to server so the client/order queries can happen quickly. That way each server is still authoritative.

  • You can definitely join the entities in code of course. You could write wrappers that sit on top of each API and then do something like this (C#):


List clientNames = new List();
var orders = OrderService.GetOrders();

foreach (var order in orders)
{
   var client = ClientService.GetClient(order.ClientId);
   clientNames.Add(client.FirstName + " " + client.LastName);
}


(Note: This is inefficient, you might want to pass a list of client IDs)

Something like the above would call two services in a simple way and then "join" them in your application. If that feels like too much work, then consider replication! =)

  • Use something like Mule (http://www.mulesoft.org/) to handle the integration of services. With Mule you can create endpoints to REST services (or any HTTP web service) and then join them together into one "message".

  • No matter what you do, if you split the data across servers, you are going to pay a little higher price for queries. I can't imagine the performance will be anywhere near what it would be if the entities were on the same server/database.

Upvotes: 1

Related Questions