Reputation: 26364
I am going to write a webserver which serves various clients through REST API. For example , I have city table which list of all the cities and the URI "/cities" will return all the cities in the CITY database. In this case , when "/cities" URI is requested , the backend code will query the database and form JSON and respond. There is another module in the server which requires the same list of cities . Do I need to reuse the same REST implementation in this case or I can directly query the database as this server side query.
Thanks
Upvotes: 0
Views: 361
Reputation: 944054
Making an HTTP request for that data wouldn't be very efficient.
Directly querying the database means duplicating code.
The best approach here is probably to write a module which accesses the database and gets the data and then use that module from both places in the code that need that data.
Upvotes: 5