2

I was trying to get some data from a Stardog triple store into Angular, but I am really struggling with getting it to work. I have no problem accessing the service from curl with the exact same headers and parameters. I also tried omitting the parameters part and just type the full url ('localhost:5820/myDB/query?reasoning=false&query=SELECT * WHERE {?s ?p ?o}') with no luck.

private _queryUrl = 'http://localhost:5820/myDB/query';

constructor(private _http: Http) {}

getData() {
    let username : string = 'admin';
    let password : string = 'admin';

    let headers = new Headers();
    headers.append('Authorization', "Basic " + btoa(username + ":" + password));
    headers.append('Content-Type', 'application/rdf+xml');
    headers.append('Accept', 'application/sparql-results+json');

    let params = new URLSearchParams();
    params.set('reasoning', 'false');
    params.set('query', 'SELECT * WHERE {?s ?p ?o}');

    let options = new RequestOptions({ headers: headers, search: params });

    return this._http
        .get(this._queryUrl, options)
        .map((res: Response) => res.json());
}
Mistalis
  • 17,793
  • 13
  • 73
  • 97
MadsHolten
  • 77
  • 1
  • 6

2 Answers2

0

You are specifying the content type as application/rdf+xml which is wrong (there is no content). As the SPARQL spec states, in this case you shouldn't have a content type and in other cases you should use either application/x-www-form-urlencoded (query via URL-encoded POST) or application/sparql-query (query via POST directly).

Evren Sirin
  • 356
  • 1
  • 2
0

Okay, so what I needed was a good night's sleep. The problem was that I had set up an in memory test api to mimic a real api. The above code works like a charm :D

MadsHolten
  • 77
  • 1
  • 6