Awesome Go

newsapi-go

CategoryThird-party APIs
SubcategoryThird-party APIs
Stars0

Go client for [NewsAPI](https://newsapi.org/)

About newsapi-go

newsapi

GoDoc Coverage Status Go Report Card

Go client implementation for the NewsAPI.

Installation

go get github.com/jellydator/newsapi-go

Usage

Simply, we create a client using NewClient function, by default only an API key is required, however some other parameters can be set using variadic option functions.

client := newsapi.NewClient("apiKey", newsapi.WithHTTPClient(&http.Client{
	Timeout: 5 * time.Second,
}))

Endpoints

Everything

Everything retrieves all articles based on provided parameters. Full endpoint documentation can be viewed here.

articles, pageCount, err := client.Everything(context.Background(), newsapi.EverythingParams{
	Query: "cryptocurrency",
})
if err != nil {
	// handle error
}
// success

Top Headlines

TopHeadlines retrieves top headlines articles based on provided parameters. Full endpoint documentation can be viewed here.

articles, pageCount, err := client.TopHeadlines(context.Background(), newsapi.TopHeadlinesParams{
	Query: "cryptocurrency",
})
if err != nil {
	// handle error
}
// success

Sources

Sources retrieves available sources based on provided parameters. Full endpoint documentation can be viewed here.

sources, err := client.Sources(context.Background(), newsapi.SourceParams{
	Categories: []newsapi.Category{
		newsapi.CategoryBusiness,
		newsapi.CategoryScience,
	},
})
if err != nil {
	// handle error
}
// success

Frequently Asked Questions

What is newsapi-go?

newsapi-go is a Third-party APIs library for the Go programming language. Go client for [NewsAPI](https://newsapi.org/)

How do I install newsapi-go?

Install newsapi-go with the Go module system using `go get jellydator/newsapi-go`. Check the repository for the current installation instructions.

What category does newsapi-go belong to?

newsapi-go is listed under Third-party APIs, specifically Third-party APIs.

← Back to Third-party APIs