joemfb / ml-common-ng

An angular module of common components for the MarkLogic REST API
https://joemfb.github.io/ml-common-ng/
2 stars 2 forks source link

Add sparqlUpdate #22

Open grtjn opened 8 years ago

grtjn commented 8 years ago

I succesfully used this in search.controller.js, but it would be nicer if this could be integrated into MLRest itself:

    mlRest.sparqlUpdate = function (query, params) {
      var accept = [
        'application/sparql-results+json'
      ];

      params = params || {};

      return mlRest.request('/graphs/sparql', {
        method: 'POST',
        params: params,
        data: query,
        headers: {
          'Accept': accept.join(', '),
          'Content-Type': 'application/sparql-update'
        }
      });
    };

Note the mlRest.request, this is a working workaround..

Also consider using POST for sparql query as well, just needs a different content-type: application/sparql-query

grtjn commented 8 years ago

While at it, consider adding this as well:

    mlRest.things = function (iri, params) {
      params = params || {};

      params.iri = iri;

      return mlRest.request('/graphs/things', {
        params: params,
        headers: {
          'Accept': 'application/n-triples'
        }
      });
    };