# better_sparql_client

A SPARQL 1.1 http client built on top of types in the [oxigraph](https://github.com/oxigraph/oxigraph) ecosystem. Exising SPARQL clients were either incomplete or used panics internally, which led to the creation of `better_sparql_client`.

## Install

```sh
cargo add better_sparql_client
```

## Usage

```rs
use url::Url;
use better_sparql_client::SparqlClient;

let client = SparqlClient::new(Url::parse("https://dbpedia.org/sparql").unwrap());

// a select query
let solutions = client
	.select(
		r#"
			SELECT ?person
			WHERE {
				?person a dbo:Artist .
			}
			LIMIT 2
		"#,
	)
	.await
	.unwrap();

// a construct query (describe works the same)
let graph = client
	.select_graph(
		r#"
			CONSTRUCT {
				?person a dbo:Artist .
			}
			WHERE {
				?person a dbo:Artist .
			}
			LIMIT 2
		"#,
	)
	.await
	.unwrap();

// an ask query
let is_true = client
	.ask(
		r#"
			ASK {
				dbr:Albert_Einstein a dbo:Scientist .
			}
		"#,
	)
	.await
	.unwrap();

// an update query
client
	.update(
		r#"
			PREFIX ex: <http://example.org/>

			INSERT DATA {
				ex:Alice ex:knows ex:Bob .
			}
		"#
	)
	.await
	.unwrap();
```

## Note on Separate Query & Update endpoints

Some services such as Apache Jena use segregated endpoints for query and updating operations. 

In this scenario, you should just instantiate two clients, one for querying and one for updating.

```rust
// use this client for queries
let query_client = SparqlClient::new(Url::parse("http://localhost:3030/main/query").unwrap());

// use this client for updates
let update_client = SparqlClient::new(Url::parse("http://localhost:3030/main/update").unwrap());
```