All Projects → barthr → newsapi

barthr / newsapi

Licence: MIT license
Go client for newsapi (https://newsapi.org/)

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to newsapi

newsapi-php
A PHP client for the News API (https://newsapi.org/docs/get-started)
Stars: ✭ 21 (-41.67%)
Mutual labels:  newsapi
ProgressiveNewsApp
A simple Progressive Web App that brought news from a variety of sources using News API.
Stars: ✭ 41 (+13.89%)
Mutual labels:  newsapi
newsAPI
API wrapper/R client for accessing https://newsapi.org
Stars: ✭ 21 (-41.67%)
Mutual labels:  newsapi
DailyNews
Daily News is a news app with good looking user interface ! Apps architecture is MVVM and used RxSwift for binding.
Stars: ✭ 31 (-13.89%)
Mutual labels:  newsapi
newsemble
API for fetching data from news websites.
Stars: ✭ 42 (+16.67%)
Mutual labels:  newsapi
NewsApp
An app that fetches latest news, headlines
Stars: ✭ 28 (-22.22%)
Mutual labels:  newsapi
Inshorts-News-API
Unofficial API of Inshorts written in Flask
Stars: ✭ 87 (+141.67%)
Mutual labels:  newsapi
HeadLines
HeadLines is a 📰 news app that delivers you with the latest news. It has interactive UI and easy to use. The app can be scrolled offline to watch your bookmarked news. Give this app a try and let me know.
Stars: ✭ 16 (-55.56%)
Mutual labels:  newsapi
News-API-Kotlin
Access the News API with Kotlin.
Stars: ✭ 35 (-2.78%)
Mutual labels:  newsapi
covid19.swift
🌐 Small iOS app to show some COVID-19 health, data, news and tweets
Stars: ✭ 25 (-30.56%)
Mutual labels:  newsapi
PopularNews
📰 News application using the API from newsapi.org
Stars: ✭ 68 (+88.89%)
Mutual labels:  newsapi
BoxFeed
News App 📱 built to demonstrate the use of SwiftUI 3 features, Async/Await, CoreData and MVVM architecture pattern.
Stars: ✭ 112 (+211.11%)
Mutual labels:  newsapi
Android-MVVM-News-App
MVVM News Application with clean code architecture & android jetpack components.
Stars: ✭ 38 (+5.56%)
Mutual labels:  newsapi
DailyFeed
iOS client for newsapi.org
Stars: ✭ 128 (+255.56%)
Mutual labels:  newsapi
flutter-MyNews
Fully customize & personalize news app, built with Flutter
Stars: ✭ 22 (-38.89%)
Mutual labels:  newsapi
NewsPin
News app for android using Kotlin, coroutines, MVP architecture
Stars: ✭ 25 (-30.56%)
Mutual labels:  newsapi

NewsAPI Go Client

GoDoc Build Status codecov Golangci

Go client for communicating with the newsapi's api.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

go get github.com/barthr/newsapi

Next, register for free at (https://newsapi.org/register), get yourself a free api key and keep it somewhere safe.

Examples

Retrieving all sources

package main

import (
	"fmt"
	"net/http"
	"context"
	"github.com/barthr/newsapi"
)

func main() {
	c := newsapi.NewClient("<API KEY>", newsapi.WithHTTPClient(http.DefaultClient))

	sources, err := c.GetSources(context.Background(), nil)

	if err != nil {
		panic(err)
	}

	for _, s := range sources.Sources {
		fmt.Println(s.Description)
	}
}

Retrieving all sources for a specific country (Great Britain in this case)

package main

import (
	"fmt"
	"net/http"
	"context"

	"github.com/barthr/newsapi"
)

func main() {
	c := newsapi.NewClient("<API KEY>", newsapi.WithHTTPClient(http.DefaultClient))

	sources, err := c.GetSources(context.Background(), &newsapi.SourceParameters{
		Country: "gb",
	})

	if err != nil {
		panic(err)
	}

	for _, s := range sources.Sources {
		fmt.Println(s.Name)
	}
}

Retrieving top headlines

package main

import (
	"fmt"
	"net/http"
	"context"

	"github.com/barthr/newsapi"
)

func main() {
	c := newsapi.NewClient("<API KEY>", newsapi.WithHTTPClient(http.DefaultClient))

	articles, err := c.GetTopHeadlines(context.Background(), &newsapi.TopHeadlineParameters{
		Sources: []string{ "cnn", "time" },
	})

	if err != nil {
		panic(err)
	}

	for _, s := range articles.Articles {
		fmt.Printf("%+v\n\n", s)
	}
}

Retrieving all articles

package main

import (
	"fmt"
	"net/http"
	"context"

	"github.com/barthr/newsapi"
)

func main() {
	c := newsapi.NewClient("<API KEY>", newsapi.WithHTTPClient(http.DefaultClient))

	articles, err := c.GetEverything(context.Background(), &newsapi.EverythingParameters{
		Sources: []string{ "cnn", "time" },
	})

	if err != nil {
		panic(err)
	}

	for _, s := range articles.Articles {
		fmt.Printf("%+v\n\n", s)
	}
}

License

This project is licensed under the MIT License

Acknowledgments

  • Inspired by github golang client
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].