Skip to content

Instantly share code, notes, and snippets.

@hendrasyp
Created February 16, 2024 02:39
Show Gist options
  • Save hendrasyp/d0ffd0000a9860663a78c492296ed9dd to your computer and use it in GitHub Desktop.
Save hendrasyp/d0ffd0000a9860663a78c492296ed9dd to your computer and use it in GitHub Desktop.
HOM API Client
string response = "";
// parameter Body, menggunakan format JSON, jika semua nilai adalah string, Anda dapat menggunakan
// tipe data Dictionary<string, string>,
// tetapi Anda juga dapat menggunakan sebuah class object untuk menampung data request.
// Call API using dictionary
Dictionary<string, string> request = new Dictionary<string, string>();
request.add("itemKey1","value");
request.add("itemKey2","value");
string jsonRequest = JsonConvert.SerializeObject(request,Formatting.None);
string response = Services.HOMAPI.HOMApi.post(partnerKey, "namaService", jsonRequest);
// Konversi hasil pemanggilan API menggunakan JsonConvert.DeserializeObject<ClassObjectAnda>(response);
ClassObjectAnda response = JsonConvert.DeserializeObject<ClassObjectAnda>(responseAPI);
if (ClassObjectAnda.metadata.code != 200)
{
throw new Exception(ClassObjectAnda.metadata.message);
}
else{
....
}
public class ClassObjectAnda{
public APIResponse_Metadata metadata {get;set;}
public List<Dictionary<string, dynamic>> results { get; set; }
}
public class APIResponse_Metadata
{
public int code { get; set; }
public string message { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment