I am developing a new microservice application that will be part of big architecture with lots of other microservices. This application needs to get content from other applications and I want to encapsulate HTTP calls into the service layer. But I noticed there are two different approaches.
Let's assume that my application will get contact information from another microservice which is deployed as User API.
Business as file
This approach has the business name as the file name. Inside the file, there is only one public method which is get
and it receives a single parameter. The method calls user-api/contact/{id}
.
Filename: contact.service.js
Method: get(id) -> contact
API as file
This approach encapsulates all communication between User API and the consumer application into a single file. There is a method for every endpoint provided for User API.
Filename: user.service.js
Method: getContact(id) -> contact
What are the pros and cons using these approaches?