title: Retrieve Data from Mysql Database in WebApi To HttpRecquest?
body: <p>I am trying to retrieve a set of data from a MySQL database in a WebAPI application and access it through HTTP request from a mobile app.  Hence I created a WebApi, a RestClient class and the class where I would show the data, this is my code.</p>
  
  <p><strong>Web API</strong></p>
  
  <pre><code>[Produces("application/json")]
  [Route("api/Blog")]
  public class BlogController : Controller
  {
      // GET: api/Blog
      [HttpGet]
      public  IEnumerable&lt;string&gt;  Get()
      {
  
      }
  
      // GET: api/Blog/5
      [HttpGet("{id}", Name = "GetBlogItems")]
      public string Get(int id)
      {
  
      }
  
      // POST: api/Blog
      [HttpPost]
      public void Post([FromBody]  RetrieveDataClass value)
      {
          string sqlstring = "server=; port= ; user id =;Password=;Database=;";
          MySqlConnection conn = new MySqlConnection(sqlstring);
          try
          {
              conn.Open();
          }
          catch (MySqlException ex)
          {
              throw ex;
          }
          string Query = "INSERT INTO test.blogtable (id,Telephone,CreatedSaved,Topic,Summary,Category,Body1,Body2,Body3,Body4)values('" + value.TopicSaved1 + "','" + Value.Telephone + "','" + Value.Created/Saved + "','" + value.TopicSaved1 + "','" +value.SummarySaved1 +"','" +value.CategoriesSaved1 +"','" +value.Body1 +"','" +value.Body2 +"','" +value.Body3 +"','" +value.Body4 +"');";
          MySqlCommand cmd = new MySqlCommand(Query, conn);
          cmd.ExecuteReader();
          conn.Close();
  
      }
  
      // PUT: api/Blog/5
      [HttpPut("{id}")]
      public void Put(int id, [FromBody]string value)
      {
      }
  
      // DELETE: api/ApiWithActions/5
      [HttpDelete("{id}")]
      public void Delete(int id)
      {
      }
  }
  </code></pre>
  
  <p>So, in my database, I have three rows with a telephone number of +233892929292, after the filter I have to get three rows. and I would also filter to only the topic and summary column.</p>
  
  <p><strong>RestClient Class</strong></p>
  
  <pre><code>   public class BlogRestClient&lt;T&gt;
  {
      private const string WebServiceUrl = "http://localhost:57645/api/Blog/";
  
      public async Task&lt;List&lt;T&gt;&gt; GetAsync()
      {
  
          var httpClient = new HttpClient();
  
          var json = await httpClient.GetStringAsync(WebServiceUrl);
  
          var taskModels = JsonConvert.DeserializeObject&lt;List&lt;T&gt;&gt;(json);
  
          return taskModels;
      }
  
  
      public async Task&lt;bool&gt; PostAsync(T t)
      {
  
          var httpClient = new HttpClient();
  
          var json = JsonConvert.SerializeObject(t);
  
          HttpContent httpContent = new StringContent(json);
  
          httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
  
          var result = await httpClient.PostAsync(WebServiceUrl, httpContent);
  
          return result.IsSuccessStatusCode;
  
      }
  
      public async Task&lt;bool&gt; PutAsync(int id, T t)
      {
          var httpClient = new HttpClient();
  
          var json = JsonConvert.SerializeObject(t);
  
          HttpContent httpContent = new StringContent(json);
  
          httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
  
          var result = await httpClient.PutAsync(WebServiceUrl + id, httpContent);
  
          return result.IsSuccessStatusCode;
      }
  
      public async Task&lt;bool&gt; DeleteAsync(int id, T t)
      {
          var httpClient = new HttpClient();
  
          var response = await httpClient.DeleteAsync(WebServiceUrl + id);
  
          return response.IsSuccessStatusCode;
      }
  }
  </code></pre>
  
  <p><strong>ModelData Class</strong></p>
  
  <pre><code>    public class ModelDataClass
      {
           public string Telephone ;
           public string Created/Saved ;
           public string TopicSaved1 ;
           public string SummarySaved1 ;
           public string CategoriesSaved1 ;
           public string Body1 ;
           public string Body2 ;
           public string Body3 ;
           public string Body4 ;
  
  
           public ModelDataClass()
           {
  
           }
      }
  </code></pre>
  
  <p>The Values for the strings in <code>ModelDataClass</code> are set in another class to post in MySQL database.  Since that is not causing the problem in question, I have not included the code. </p>
  
  <p><strong>RetrieveDataClass</strong></p>
  
  <pre><code> public class RetrieveDataClass
      {
           public string Topic ;
           public string Summary ;
  
           public RetrieveDataClass()
           {
              GetDataEvent();
              AddBlog();
           }
  
            public void GetDataEvent()
           {
            BlogRestClient&lt;ModelDataClass&gt; restClient = new 
            BlogRestClient&lt;ModelDataClass&gt;();
              await restClient.GetAsync();
           }
  
  
        public ObservableCollection&lt;ModelDataClass&gt; BlogItems = new  
        ObservableCollection&lt;ModelDataClass&gt;();
  
      public void AddBlog()
      {
          BlogListView.ItemsSource = BlogItems;
      }
     }
  </code></pre>
  
  <p><strong>Question1</strong>
  How do I retrieve the data from, Mysql, to WebAPI accessed through the REST client class(It's for mobile so I have to use Http request)?</p>
  
  <p><strong>Question2</strong>
  I would like to create a listView for each row I retrieve through the MySQL database.  With the heading being the data in the topic column and the subheading is with the data in summary column.</p>