简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM