we have a working .net core api which takes 3 values and processes the. You can see the screenshot below, which is having placeholder for all the fields.In The message field we were able to pass both JSON as well as XML data which our api was able to consume.
Now after we have updated our code to latest .net version you can see that all three input fields are taking string as default value. Moreover the main issue is that is we send a json value in Message field we get a 400 exception saying message field cannot be empty.
My controller code and class code remains same mentioned below :-
[HttpPost("Produce/v2")]
public async Task<IActionResult> ProduceForm([FromForm] KafkaPublisherRequest kafkaPublisherRequest)
{
if (kafkaPublisherRequest == null || !ModelState.IsValid)
{
return BadRequest();
}
_logger.LogInformation($"Started Publishing into Kafka Topic : {kafkaPublisherRequest.Topic}, Key :{kafkaPublisherRequest.Key}");
//Main code
return Ok(new ServiceResult(ServiceState.Completed, kafkaPublisherRequest.Key, "Produced Successfully"));
}
And here is my model class :-
public class KafkaPublisherRequest
{
[Required]
public string Key { get; set; }
[Required]
public string Message { get; set; }
[Required]
public string Topic { get; set; }
public Dictionary<string, string> Headers { get; set; }
}