How to consume/deserialize strapi v4 endpoints in C#?

needed support for array / non array, so created plural and singular roots

//use this if you come across a root object that is not an array
public class StrapiRoot<T> where T: AttributeWrapper {        
    [JsonProperty("data")]
    public DataWrapper<T> data { get; set; }
    
    public T datum {
        get
        {
            return data.attributes;
        }
    }
}

//use this for object which are array's at the root
public class StrapiPluralRoot<T> where T: AttributeWrapper {        
    [JsonProperty("data")]
    public List<DataWrapper<T>> data { get; set; }
    
    public List<T> datum {
        get
        {
            if(data == null) {
                return new List<T>();
            }
            
            return data.Select(x => x.attributes).ToList();
        }
    }
}
1 Like