0

I have a microservice endpoint that gets a list of company details from the DB. The URL pattern looks like this.

GET https://example.com/api/v1/companies

I need to develop another URL that fetches only the company names from DB. I understand I can reuse the same URL, but to fetch only one column i don't want to fetch all columns.

Please guide me how to have the url pattern for this case.

Ex: GET https://example.com/api/v1/companies/companyNames?

ByteChip
  • 1
  • 1

1 Answers1

0

We should not increase number of services exposed until it is really needed. I will recommend re-using the same service with format:

GET https://example.com/api/v1/companies?col=name

If col parameter is blank you can assume to return all columns. This will help you re-use the codebase; minimal changes; and lots of flexibility in future; and less confusion for end consumer.

Deepak Singhal
  • 10,568
  • 11
  • 59
  • 98