mercredi 18 mars 2020

How to create one Model class to test multiple API calls that required different Json payload?

I have a several API under one service. The APIs take different Json payloads. I want to create one model class with the attributes and values and set them. Can this be achieve with one model class to use for the several APIs. For example I have one of the API which takes a Json id and name and another API that takes userID and color. How can I call the specific attritubes and values to apply when sending the requesting to the specific API that requires those data. I am using JsonConvert.SerializeObject(Model) in my Sendrequest

Ex:

public class Model
{ 
        public int id { get; set; }
        public string name { get; set; }
        public int userID { get; set; }
        public string color { get; set; }

   public Model()
{
    this.id = 3;
   this.name = "john";
   this.userId = 101;
   this.color = "blue"

}

}

Aucun commentaire:

Enregistrer un commentaire