NEWS Application using New York Times API

Hello, I am back again with a new article; In this article, I will be showing how I built a News Website using NY Times API

Consider liking and sharing the article.

Let’s get started,

Step 1 – Register Application at NY Times Developers…


This content originally appeared on DEV Community and was authored by SnowBit

Hello, I am back again with a new article; In this article, I will be showing how I built a News Website using NY Times API

Consider liking and sharing the article.

Let's get started,

Step 1 - Register Application at NY Times Developers

Step 2 - Code

  • Fetch (Note API KEY in the code has been deprecated use your OWN API KEY)
await fetch('https://api.nytimes.com/svc/mostpopular/v2/viewed/1.json?api-key=iDFG30D2aGpr4OWWSJ6UBMBQh2S7oZpW')
.then(d => d.json())
.then(response => {})
  • Fetching Results
for(var i = 0; i < response.results.length; i++){
            const output = document.getElementById('output');

            try{
                output.innerHTML += `
                    <div class="card">
                    <div class="card-body">
                    <img src="${response.results[i]['media'][0]['media-metadata'][2].url}" class="card-img-top" alt="${response.results[i]['media'][0].caption}" title="${response.results[i]['media'][0].caption}"><br>
                    <h2 class="card-title">${response.results[i].title}</h2>
                    <div class="card-text">
                        <p>${response.results[i].abstract}</p>
                    </div>
                    </div>
                    </div>
                    <br>
                    `
                console.log(response.results[i]['media'][0].caption);
            }
            catch(err){
                console.log(err);
            }
        }
  • Result Result

Consider liking the article if you learnt something new.


This content originally appeared on DEV Community and was authored by SnowBit


Print Share Comment Cite Upload Translate Updates
APA

SnowBit | Sciencx (2021-12-10T07:10:52+00:00) NEWS Application using New York Times API. Retrieved from https://www.scien.cx/2021/12/10/news-application-using-new-york-times-api/

MLA
" » NEWS Application using New York Times API." SnowBit | Sciencx - Friday December 10, 2021, https://www.scien.cx/2021/12/10/news-application-using-new-york-times-api/
HARVARD
SnowBit | Sciencx Friday December 10, 2021 » NEWS Application using New York Times API., viewed ,<https://www.scien.cx/2021/12/10/news-application-using-new-york-times-api/>
VANCOUVER
SnowBit | Sciencx - » NEWS Application using New York Times API. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/10/news-application-using-new-york-times-api/
CHICAGO
" » NEWS Application using New York Times API." SnowBit | Sciencx - Accessed . https://www.scien.cx/2021/12/10/news-application-using-new-york-times-api/
IEEE
" » NEWS Application using New York Times API." SnowBit | Sciencx [Online]. Available: https://www.scien.cx/2021/12/10/news-application-using-new-york-times-api/. [Accessed: ]
rf:citation
» NEWS Application using New York Times API | SnowBit | Sciencx | https://www.scien.cx/2021/12/10/news-application-using-new-york-times-api/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.