user4912134
user4912134

Reputation: 1043

Return two responses different responses from the Rest API

I am having an API which returns the response in the format [{"Acc":"adm","Cnt":"087","Yr":"17"}].

 var response_EndPoint = await client_EndPoint.GetAsync(EndPoint_URL);
 var projectDetails = await response_EndPoint.Content.ReadAsAsync<Model[]>();
 return Ok(projectDetails);

Now I am checking if there is a way to extend this Rest API to send two responses one is [{"Acc":"adm","Cnt":"087","Yr":"17"}] and the other is 17-adm-087

foreach (Model res in projectName)
{
 string serviceResponse = string.Format("{0}-{1}-{2}", res.Yr,res.Acc, res.Cnt);
}  

I am constructing the string but not sure if there is any possibility of sending both the responses.

Upvotes: 0

Views: 2454

Answers (1)

CodeArtist
CodeArtist

Reputation: 5684

You cannot send two responses from one endpoint but you can merge the result into one response. If you need two totally different responses you have two options.

  1. Implement two REST endpoints
  2. In one REST endpoint pass an additional parameter and based on that parameter return different results, but you will have to make two calls to that endpoint.

Upvotes: 3

Related Questions