AlexJames
Well-known member
- Joined
- Mar 20, 2020
- Messages
- 65
- Programming Experience
- 10+
Hi All
I'm currently consuming a REST api and i need some guidance on reading the response data. My experience with reading this type of data is very minimal and i'm trying to find the best way to do it.
below is the code for getting the API data.
I'm using the code below to call the above method and this is where I need to process the data.
What is the best way to read this data ? there are options for json, xml readers, leave it as text etc. so many choices. Any guidance on this would be greatly appreciated.
I'm currently consuming a REST api and i need some guidance on reading the response data. My experience with reading this type of data is very minimal and i'm trying to find the best way to do it.
below is the code for getting the API data.
C#:
public string ModitarWebRequestCall()
{
string apiUrl = "https://api.moditar.com/Document/GetContent";
string username = "JohnDoe";
string password = "Password123";
string collection = "ea85fbf3-5858-4348-bcab-08a8f39ad30c";
string markasread = "False";
var request = (HttpWebRequest)WebRequest.Create(apiUrl);
request.Method = "GET";
request.Accept = "application/xml";
request.Headers.Add("username", username);
request.Headers.Add("password", password);
request.Headers.Add("collection", collection);
request.Headers.Add("Markasread", markasread);
string content = string.Empty;
try
{
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
using (var sr = new StreamReader(stream))
{
content = sr.ReadToEnd();
sr.Close();
Console.WriteLine("Data received from Moditar");
}
}
}
return content;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
I'm using the code below to call the above method and this is where I need to process the data.
C#:
public void ProcessDatafromModitarApi()
{
var getData = new ModitarApiConnection();
getData.ModitarWebRequestCall();
}
What is the best way to read this data ? there are options for json, xml readers, leave it as text etc. so many choices. Any guidance on this would be greatly appreciated.