3.14 (Exercise) Building a new GET request

In this exercise, I want you to apply everything you have learned in this section so far to our news application.

You will need to fetch the latest news from https://newsdata.io/documentation#latest-news

I also updated the UI to look a bit prettier as of now:

Instructions:

  • Check out starting code at section_3_request_start from our NewsRepo - https://github.com/nsmirosh/KMP-for-Android-devs
  • Get an API key from newsdata.io (instructions below)
  • I’ve implemented all of the boilerplate for you, like the ViewModel, Repos, appropriate directories and files - your job is to only implement the TODOs
  • Import Ktor and build HTTP clients for Android & iOS
  • Make a GET request to the latest news endpoint - https://newsdata.io/documentation#latest-news
  • You will need to append your API key as a parameter, so your full request URL will look something like:

  https://newsdata.io/api/1/latest?apikey=YOUR_API_KEY_HERE

Hardcode your API key for now - but DO NOT commit it to the repository. We will extract it and store it safely in further lessons.

Your task is to simply verify that we received a response as of now. But do not parse it yet, as we need to cover a few things before we can actually parse it. If you get a 200 response - you’re good.

However, if you’re feeling brave - feel free to parse everything yourself.

To get an API key: 

  1. First go to https://newsdata.io/
  2. Follow the instruction on the screenshots below:

Complete and Continue  
Discussion

0 comments