I have a third-party REST api where I should pass content as JSON. Parameters look like:
{
id: id,
fields:
{
"TYPE_ID": "JOURNALIST",
"SOURCE_ID": "CONFERENCE"
},
params: { "REGISTER_SONET_EVENT": "Y" }
}
There are a lot of methods and count of parameters a variable. There could be only "id", or only "fields", also "fields" and "params" content could be varibale too.
I'm trying to make well designed wrapper for it using C#.
Now I'v created this classes to wrap request parameters and serialize to JSON:
public class BaseRequest
{
public IEnumerable<RequestField> Parameters{ get; set; }
}
public class RequestField
{
public string FieldName { get; set; }
public object FieldValue { get; set; }
}
Where "FieldValue" could be a RequestField.
But I think it is not a good approach. Could you advise me any flexable and solid solution to use? Maybe any pattern for it or example of wrapper?
Aucun commentaire:
Enregistrer un commentaire