Created
February 16, 2024 02:39
-
-
Save hendrasyp/d0ffd0000a9860663a78c492296ed9dd to your computer and use it in GitHub Desktop.
HOM API Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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