I am using Postman to make a Get call. In the URL I have optional parameters with underscore in it. I want to assign those values to a class by using DataContract but I can't-do it. If I read them separately then there is no issue.
This is new to me so exploring what is the best approach to do it. Found some links where the suggestion is to go for an individual parameter but want to make sure I am not missing anything here.
Call: http://{{url}}/Host?host_name=Test&host_zipcode=123&host_id=123
Working: I can read these parameter values if I read them as an individual parameter.
[HttpGet]
[Route("api/Host")]
public async Task<HostResponse> GetHostInfo([FromUri (Name = "host_name")] string hostName, [FromUri (Name = "host_zipcode")] string hostZipCode, [FromUri(Name = "host_id")] string hostId)
{
}
Not Working: When I try to use class by using DataContract, I can't read it.
[HttpGet]
[Route("api/Host")]
public async Task<HostResponse> GetHostInfo([FromUri] HostInfo hostInfo)
{
}
[DataContract]
public class HostInfo
{
[DataMember(Name = "host_name")]
public string HostName { get; set; }
[DataMember(Name = "host_zipcode")]
public string HostZipCode { get; set; }
[DataMember(Name = "host_id")]
public string HostId { get; set; }
}
I also tried:
public class DeliveryManagerStatus
{
[JsonProperty(PropertyName = "country")]
public string Country { get; set; }
[JsonProperty(PropertyName = "delivery_provider")]
public string DeliveryProvider { get; set; }
[JsonProperty(PropertyName = "job_id")]
public string JobId { get; set; }
}
How can I assign these properties to a class?