httpclient

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

httpclient implements an API client for NewsAPI https://newsapi.org/docs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	Source      Source    `json:"source"`
	Title       string    `json:"title"`
	Author      string    `json:"author,omitempty"`
	Description string    `json:"description,omitempty"`
	Url         string    `json:"url,omitempty"`
	ImageUrl    string    `json:"urlToImage,omitempty"`
	PublishedAt time.Time `json:"publishedAt"`
	Content     string    `json:"content,omitempty"`
}

Article is a news article

func (Article) String

func (a Article) String() string

type ArticlesRequest

type ArticlesRequest struct {
	Query          string `json:"q,omitempty" help:"Search keywords or phrases"`
	SearchIn       string `` /* 137-byte string literal not displayed */
	Sources        string `` /* 134-byte string literal not displayed */
	Domains        string `json:"domains,omitempty" help:"A comma-separated string of domains (eg bbc.co.uk, techcrunch.com) to restrict the search to"`
	ExcludeDomains string `json:"excludeDomains,omitempty" help:"A comma-separated string of domains to remove from the results"`
	From           string `` /* 142-byte string literal not displayed */
	To             string `json:"to,omitempty" help:"A date and optional time for the newest article allowed. ISO 8601 format"`
	Language       string `json:"language,omitempty" help:"The 2-letter ISO-639-1 code of the language you want to get articles for"`
	SortBy         string `json:"sortBy,omitempty" help:"The order to sort the articles in" enum:"relevancy,popularity,publishedAt"`
	PageSize       int    `json:"pageSize,omitempty" help:"The number of results to return per page (1-100)" min:"1" max:"100"`
	Page           int    `json:"page,omitempty" help:"Use this to page through the results" min:"1"`
}

ArticlesRequest is a request to search for articles

func (*ArticlesRequest) Values

func (r *ArticlesRequest) Values() url.Values

Values returns the request as URL query parameters

type Client

type Client struct {
	*client.Client
}

func New

func New(apiKey string, opts ...client.ClientOpt) (*Client, error)

New returns a client for NewsAPI with the API key. The endpoint can be replaced with client.OptEndpoint, for example for testing.

func (*Client) Articles

func (c *Client) Articles(ctx context.Context, req *ArticlesRequest) ([]Article, error)

Articles returns the articles matching the request

func (*Client) Headlines

func (c *Client) Headlines(ctx context.Context, req *HeadlinesRequest) ([]Article, error)

Headlines returns the top headlines matching the request

func (*Client) Sources

func (c *Client) Sources(ctx context.Context, req *SourcesRequest) ([]Source, error)

Sources returns the news sources matching the request

type HeadlinesRequest

type HeadlinesRequest struct {
	Query    string `json:"q,omitempty" help:"Keywords or phrases to search for in the article title and body"`
	Category string `` /* 146-byte string literal not displayed */
	Country  string `json:"country,omitempty" help:"The 2-letter ISO 3166-1 code of the country you want to get headlines for"`
	Sources  string `` /* 178-byte string literal not displayed */
	Language string `json:"language,omitempty" help:"The 2-letter ISO-639-1 code of the language you want to get headlines for"`
	PageSize int    `json:"pageSize,omitempty" help:"The number of results to return per page (1-100)" min:"1" max:"100"`
	Page     int    `json:"page,omitempty" help:"Use this to page through the results" min:"1"`
}

HeadlinesRequest is a request for the top headlines

func (*HeadlinesRequest) Values

func (r *HeadlinesRequest) Values() url.Values

Values returns the request as URL query parameters

type Source

type Source struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Url         string `json:"url,omitempty"`
	Category    string `json:"category,omitempty"`
	Language    string `json:"language,omitempty"`
	Country     string `json:"country,omitempty"`
}

Source is a news source, such as a newspaper or blog

func (Source) String

func (s Source) String() string

type SourcesRequest

type SourcesRequest struct {
	Category string `` /* 144-byte string literal not displayed */
	Language string `json:"language,omitempty" help:"The 2-letter ISO-639-1 code of the language you want to get sources for"`
	Country  string `json:"country,omitempty" help:"The 2-letter ISO 3166-1 code of the country you want to get sources for"`
}

SourcesRequest is a request for news sources

func (*SourcesRequest) Values

func (r *SourcesRequest) Values() url.Values

Values returns the request as URL query parameters

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL