0

I want to filter some of the data from response when request come from Dev1 server and when request from other server then it shows all values in my model in web api , how should I handle it. as well as i am setting the http header in Api01 as public and check that header in Api2 request.

Exp internally Api1(Dev01) calls the Api2(Dev02)

1.Request from Api01 (Dev01) then -> Dev02 return some of the values in resp. 2.Request any other server then-> Dev02 return all values in response.

1 Answers1

0

You shouldn't care what machine a request comes from in order to hide some fields in your response. Use authorization for that.

If you can't do that, and you really want to alter the response based on which machine calls your API, then obtain the caller's IP address and act on that: Asp Net Web API 2.1 get client IP address.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • yes you are right but i don't want to use the authorization here. I only want to fittler some of the data form my model. – Gaurav Satpute Apr 17 '19 at 11:37
  • exp: supposed I have response model with some property{A,B,C,D} so when request come from Api01 then it only return {A,B} not C and D. Here both Api's used same model M1 – Gaurav Satpute Apr 17 '19 at 11:38
  • Yeah so set them to null if the request comes from a certain machine. Optionally configure the JSON formatter to ignore null values. – CodeCaster Apr 17 '19 at 11:50
  • Can you plz explain little bit more. how to handle this situation in model. becoz my model is common in both Api01 and Api02. Can I set the some custom attribute on all property in side mode. so when that set that attribute then it will show only that fields on which that attribute mentioned. – Gaurav Satpute Apr 18 '19 at 03:35