repo

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: MIT Imports: 12 Imported by: 0

README

repo

Package repo provides a simple http client for interacting with sparql endpoints.

It comes with a series of convenience options for setting auth, or caching responses.

The client contained in this package also serves as a reference implementation for any developer who has more complex requirements than this very simple client provides


Readme created from Go doc with goreadme

Documentation

Overview

Package repo provides a simple http client for interacting with sparql endpoints.

It comes with a series of convenience options for setting auth, or caching responses.

The client contained in this package also serves as a reference implementation for any developer who has more complex requirements than this very simple client provides

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithBasicAuth

func WithBasicAuth(username, password string) func(*Repo) error

WithBasicAuth configures Repo to use basic authentication on HTTP requests.

func WithCache

func WithCache(c httpcache.Cache) func(*Repo) error

WithCache takes a httpcache.Cache, thus providing a way of caching sparql queries which may be otherwise slow, or where the data returned changes infrequently.

It may be used as:

cache := httpcache.NewMemoryCache()
repo := sparql.NewRepo("localhost:8080/sparql", sparql.WithCache(cache))

This uses the default httpcache in-memory cache in requests

func WithDigestAuth

func WithDigestAuth(username, password string) func(*Repo) error

WithDigestAuth configures Repo to use digest authentication on HTTP requests.

func WithHeader

func WithHeader(key, value string) func(*Repo) error

WithHeader sets a header on requests to a repo

These headers can be chained, both with themselves and with another set of repo opts, such as

repo, err := repo.New("https://example.com", repo.WithCache(c), repo.WithHeader("max-age", "1800"), repo.WithHeader("user-agent", "my-app"))

It's better to set these options last though, just in case a prior opt mucks about with headers or clients or roundtrippers

func WithTimeout

func WithTimeout(t time.Duration) func(*Repo) error

WithTimeout instructs the underlying HTTP transport to timeout after given duration.

Types

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo represents a RDF repository, assumed to be queryable via the SPARQL protocol over HTTP.

func New

func New(addr string, options ...func(*Repo) error) (r *Repo, err error)

New creates a new representation of a RDF repository. It takes a variadic list of functional options which can alter the configuration of the repository.

func (Repo) Query

func (r Repo) Query(query string) (*sparql.Results, error)

Query performs a SPARQL HTTP request to the Repo, and returns the parsed application/sparql-results+json response.

These lookups are expected to be idempotent, and as such use http.MethodGet requests. See: Repo.Update for requests which use http.MethodPost

func (*Repo) SetOption

func (r *Repo) SetOption(options ...func(*Repo) error) error

SetOption takes one or more option function and applies them in order to Repo.

func (Repo) Update

func (r Repo) Update(query string) (*sparql.Results, error)

Update performs a SPARQL HTTP request to the Repo, and returns the parsed application/sparql-results+json response.

These queries are made via an http.MethodPost and, so, are expected to change state.

Functionally these requests differ very little from requests made via Repo.Query; and in fact there's nothing that says a POST'd request *must* update state. The difference is purely to allow for the caching of GET requests

Jump to

Keyboard shortcuts

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