Skip to content

nurzhanme/Gnews

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gnews

Gnews is a C# wrapper for the GNews API. With Gnews, you can easily integrate the GNews API into your C# application and access news articles and metadata from thousands of news sources worldwide.

If you like this project please give a star and a cup of coffee =)

"Buy Me A Coffee"

Installation

NuGet Badge

To install Gnews, you can use the NuGet package manager in Visual Studio. Simply search for "Gnews" and click "Install".

Alternatively, you can install Gnews using the command line:

Install-Package Gnews

Getting Started

Obtain valid GNews API key from the https://gnews.io/.

Without using dependency injection:

var gnewsClient = new GnewsClient(new GnewsClientOptions()
{
    ApiKey = Environment.GetEnvironmentVariable("MY_GNEWS_API_KEY")
});

Using dependency injection:

In your secrets.json or other settings.json

"GnewsClientOptions": {
  //"ApiKey": "Your api key goes here",
  //"ApiBaseAddress": "If api base has been changed (optional. by default: https://gnews.io/api/v4/)"
},

Program.cs

serviceCollection.AddGnewsClient();

or using Environment Variable

serviceCollection.AddGnewsClient(settings => { settings.ApiKey = Environment.GetEnvironmentVariable("MY_GNEWS_API_KEY"); });

NOTE: do NOT put your API key directly to your source code.

After injecting your service you will be able to get it from service provider

var gnewsClient = serviceProvider.GetRequiredService<GnewsClient>();

or injecting in the constructor of your class

public class NewsService
{
    private readonly GnewsClient _gnewsClient;
    
    public NewsService(GnewsClient gnewsClient)
    {
        _gnewsClient = gnewsClient;
    }
}

Search request

var respone = await gnewsClient.Search(new SearchRequest { Q = "Bitcoin" });

foreach (var article in respone.Articles)
{
    Console.WriteLine(article.Title);
}

more details about search request https://gnews.io/docs/v4#search-endpoint

About

NET Client for Gnews API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages