📚 newsapi-go - Awesome Go Library for Third-party APIs

Go client for [NewsAPI](https://newsapi.org/)
🏷️ Third-party APIs
📂 Third-party APIs
⭐ 0 stars
Detailed Description of newsapi-go
newsapi
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
