List Info

Thread: Using POST instead of GET for Sparql queries




Using POST instead of GET for Sparql queries
user name
2007-09-22 19:41:06
Hi ActiveRDF crew,

First off, thanks very much for an excellent library.

I'm using ActiveRDF as a wrapper around hand-written SPARQL queries, a la  "results = SPARQL.execute_sparql_query(query_string)"

I've run into the problem that some of my queries are overloading the buffer on my server (currently Jetty, wrapping Joseki) because they are encoded in the URL of a GET request. I know this is a problem with the server, but I think the simpler workaround would be to modify ActiveRDF to put the parameters in the body of a POST request instead of the URL of a GET.

Right now, the SparqlAdapter code encodes the query as follows:

  ;  def execute_sparql_query(qs, header=nil, &block)
    header = header(nil) if header.nil?
        # encoding query string in URL
        url = "#url?query=#{CGI.escape(qs)}";

Has anyone adapted this to put it in the body of a POST request? Is this an easy thing to do?

Thanks!
Ted

--
Edward Benson
http://www.edwardbenson.com/
Re: Using POST instead of GET for Sparql queries
user name
2007-09-26 01:48:00
On 23.09.2007, at 02:41, Edward Benson wrote:
> I've run into the problem that some of my queries are
overloading  
> the buffer on my server (currently Jetty, wrapping
Joseki) because  
> they are encoded in the URL of a GET request. I know
this is a  
> problem with the server, but I think the simpler
workaround would  
> be to modify ActiveRDF to put the parameters in the
body of a POST  
> request instead of the URL of a GET.
>
> Right now, the SparqlAdapter code encodes the query as
follows:
>
>     def execute_sparql_query(qs, header=nil,
&block)
>     header = header(nil) if header.nil?
>         # encoding query string in URL
>         url = "#url?query=#{CGI.escape(qs)}"
>
> Has anyone adapted this to put it in the body of a POST
request? Is  
> this an easy thing to do?


I guess it is possible. Right now neither Eyal nor me has a
lot of  
time to look how to implement that. Maybe if you find out
how to  
construct a POST query, then I could implement it.

It would also be important to see what the SPARQL spec says:
Is it  
important if GET or POST are used? Are there differences?
Does this  
have to be negotiated between client and server ? 
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf

Re: Using POST instead of GET for Sparql queries
user name
2007-09-26 02:39:51
The Rails team once did the mistake of using POST instead of GET to do what GET is supposed to do. Initially it worked but nevertheless they learned that it is wrong practice. Imagine when a google bot comes in and finds a destructive POST link...

Are you convinced that Joseki would be faster with POST instead of GET? Would it be easier to switch to Virtuoso, which should be faster?


2007/9/26, Benjamin Heitmann < benjamin.heitmannderi.org">benjamin.heitmannderi.org&gt;:

On 23.09.2007, at 02:41, Edward Benson wrote:
>; I've run into the problem that some of my queries are overloading
> the buffer on my server (currently Jetty, wrapping Joseki) because
&gt; they are encoded in the URL of a GET request. I know this is a
> problem with the server, but I think the simpler workaround would
> be to modify ActiveRDF to put the parameters in the body of a POST
> request instead of the URL of a GET.
>
> Right now, the SparqlAdapter code encodes the query as follows:
>
>&nbsp;   ; def execute_sparql_query(qs, header=nil, &block)
; &nbsp;  header = header(nil) if header.nil?
; &nbsp; &nbsp; &nbsp;  # encoding query string in URL
>&nbsp; &nbsp;   ; &nbsp; url = "#url?query=#{CGI.escape (qs)}&quot;
>
&gt; Has anyone adapted this to put it in the body of a POST request? Is
> this an easy thing to do?


I guess it is possible. Right now neither Eyal nor me has a lot of
time to look how to implement that. Maybe if you find out how to
construct a POST query, then I could implement it.

It would also be important to see what the SPARQL spec says: Is it
important if GET or POST are used? Are there differences? Does this
have to be negotiated between client and server ?
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org">ActiveRDFlists.deri.org
http://lists.deri.org/mailman/listinfo/activerdf

Re: Using POST instead of GET for Sparql queries
user name
2007-09-26 13:20:43
Benjamin --

Thanks for your response. I added the ability to choose between POST and GET in the SPARQL adapter. It seems to be working well. I've included my changes below if you'd like to incorporate them into the ActiveRDF code.

Scanning the SPARQL language spec, I can't find the endpoint definition, so I'm not sure if POST is supported. Nevertheless, the inability to perform lengthy SPARQL queries through GET seems to necessitate the need for POST-based queries.

Mikael -> I agree with you 100% that POST & GET should be used in RESTful / Old-Skool HTTP fashion when it comes to the web, but I think SPARQL is a special case. A SPARQL URI does not represent a resource, it represents a service endpoint. It is a service that happens to be offered over HTTP rather than a interlinked part of the WWW. When Seaborne et al's, SPARQL/Update changes are integrated into sparql, they will be done so as part of the language and not using the HTTP commands. So I think this is one case where it is alright to treat HTTP as nothing more than a transport, and the various HTTP commands as just various different sub-types of that transport with different properties.

Cheers,
Ted

Changes
-----------------

 In the initialize constructor, I added the line:

&nbsp; &nbsp;  &nbsp;  request_method = params[:request_method] || :get

And then in the execute_sparql_query, I replaced some of the existing code with the following:

 &nbsp;   &nbsp;  begin
 &nbsp;   &nbsp;   &nbsp;  if request_method == :get
 ; &nbsp;  &nbsp;   &nbsp;   &nbsp;  url = "#url?query=#{CGI.escape(qs)}";
 &nbsp;   &nbsp;   &nbsp;   &nbsp;  url = url.gsub(&quot;DISTINCT", "&quot;) if yars2
&nbsp; &nbsp;  &nbsp;   &nbsp;   &nbsp;  response = ''
 &nbsp;   &nbsp;   &nbsp;   &nbsp;  open(url, header) do |f|
   ;  &nbsp;   &nbsp;   &nbsp;   &nbsp;  response = f.read
&nbsp; &nbsp;  &nbsp;   &nbsp;   &nbsp;  end
   ;  &nbsp;   &nbsp;  else
 ; &nbsp;  &nbsp;   &nbsp;   &nbsp;  res = Net::HTTP.post_form(URI.parse(url),{';query'=>qs})&nbsp; &nbsp;  &nbsp;   &nbsp;   &nbsp; 
 &nbsp;   &nbsp;   &nbsp;  end
   ;  &nbsp;   &nbsp;  response = res.body
&nbsp;    &nbsp;  rescue ....






On 9/26/07, Benjamin Heitmann < benjamin.heitmannderi.org"> benjamin.heitmannderi.org&gt; wrote:

On 23.09.2007, at 02:41, Edward Benson wrote:
&gt; I've run into the problem that some of my queries are overloading
> the buffer on my server (currently Jetty, wrapping Joseki) because
&gt; they are encoded in the URL of a GET request. I know this is a
> problem with the server, but I think the simpler workaround would
> be to modify ActiveRDF to put the parameters in the body of a POST
> request instead of the URL of a GET.
>
> Right now, the SparqlAdapter code encodes the query as follows:
>
>&nbsp;   ; def execute_sparql_query(qs, header=nil, &block)
; &nbsp;  header = header(nil) if header.nil?
; &nbsp; &nbsp; &nbsp;  # encoding query string in URL
>&nbsp; &nbsp;   ; &nbsp; url = "#url?query=#{CGI.escape (qs)}&quot;
>
&gt; Has anyone adapted this to put it in the body of a POST request? Is
> this an easy thing to do?


I guess it is possible. Right now neither Eyal nor me has a lot of
time to look how to implement that. Maybe if you find out how to
construct a POST query, then I could implement it.

It would also be important to see what the SPARQL spec says: Is it
important if GET or POST are used? Are there differences? Does this
have to be negotiated between client and server ?
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org">ActiveRDFlists.deri.org
http://lists.deri.org/mailman/listinfo/activerdf



--
Edward Benson
http://www.edwardbenson.com/
Re: Using POST instead of GET for Sparql queries
user name
2007-09-26 13:48:37
Correction:

The line "response = res.body&quot; should have been before the "end&quot; statement. Sorry 'bout that.

Ted

On 9/26/07, Edward Benson < edward.bensongmail.com">edward.bensongmail.com> wrote:
Benjamin --

Thanks for your response. I added the ability to choose between POST and GET in the SPARQL adapter. It seems to be working well. I've included my changes below if you'd like to incorporate them into the ActiveRDF code.

Scanning the SPARQL language spec, I can't find the endpoint definition, so I'm not sure if POST is supported. Nevertheless, the inability to perform lengthy SPARQL queries through GET seems to necessitate the need for POST-based queries.

Mikael -> I agree with you 100% that POST & GET should be used in RESTful / Old-Skool HTTP fashion when it comes to the web, but I think SPARQL is a special case. A SPARQL URI does not represent a resource, it represents a service endpoint. It is a service that happens to be offered over HTTP rather than a interlinked part of the WWW. When Seaborne et al's, SPARQL/Update changes are integrated into sparql, they will be done so as part of the language and not using the HTTP commands. So I think this is one case where it is alright to treat HTTP as nothing more than a transport, and the various HTTP commands as just various different sub-types of that transport with different properties.

Cheers,
Ted

Changes
-----------------

 In the initialize constructor, I added the line:

&nbsp; &nbsp;  &nbsp;  request_method = params[:request_method] || :get

And then in the execute_sparql_query, I replaced some of the existing code with the following:

 &nbsp;   &nbsp;  begin
 &nbsp;   &nbsp;   &nbsp;  if request_method == :get
 &nbsp;   &nbsp;   &nbsp;   &nbsp;  url = "#url?query=#{CGI.escape(qs)}";
 &nbsp;   &nbsp;   &nbsp;   &nbsp;  url = url.gsub(&quot;DISTINCT", "&quot;) if yars2
&nbsp; &nbsp;  &nbsp;   &nbsp;   &nbsp;  response = ''
 &nbsp;   &nbsp;   &nbsp;   &nbsp;  open(url, header) do |f|
   ;  &nbsp;   &nbsp;   &nbsp;   &nbsp;  response = f.read
&nbsp; &nbsp;  &nbsp;   &nbsp;   &nbsp;  end
   ;  &nbsp;   &nbsp;  else
 ; &nbsp;  &nbsp;   &nbsp;   &nbsp;  res = Net::HTTP.post_form(URI.parse(url),{';query'=>qs})&nbsp; &nbsp;  &nbsp;   &nbsp;   &nbsp; 
 &nbsp;   &nbsp;   &nbsp;  end
   ;  &nbsp;   &nbsp;  response = res.body
&nbsp;    &nbsp;  rescue ....







On 9/26/07, Benjamin Heitmann < benjamin.heitmannderi.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> benjamin.heitmannderi.org&gt; wrote:

On 23.09.2007, at 02:41, Edward Benson wrote:
&gt; I've run into the problem that some of my queries are overloading
> the buffer on my server (currently Jetty, wrapping Joseki) because
&gt; they are encoded in the URL of a GET request. I know this is a
> problem with the server, but I think the simpler workaround would
> be to modify ActiveRDF to put the parameters in the body of a POST
> request instead of the URL of a GET.
>
> Right now, the SparqlAdapter code encodes the query as follows:
>
>&nbsp;   ; def execute_sparql_query(qs, header=nil, &block)
; &nbsp;  header = header(nil) if header.nil?
; &nbsp; &nbsp; &nbsp;  # encoding query string in URL
>&nbsp; &nbsp;   ; &nbsp; url = "#url?query=#{CGI.escape (qs)}&quot;
>
> Has anyone adapted this to put it in the body of a POST request? Is
> this an easy thing to do?


I guess it is possible. Right now neither Eyal nor me has a lot of
time to look how to implement that. Maybe if you find out how to
construct a POST query, then I could implement it.

It would also be important to see what the SPARQL spec says: Is it
important if GET or POST are used? Are there differences? Does this
have to be negotiated between client and server ?
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">ActiveRDFlists.deri.org
http://lists.deri.org/mailman/listinfo/activerdf






--
Edward Benson
http://www.edwardbenson.com/
Re: Using POST instead of GET for Sparql queries
user name
2007-10-01 04:35:22
On 09/26/07/09/07 14:20 -0400, Edward Benson wrote:
>Benjamin --
>
>Thanks for your response. I added the ability to choose
between POST and GET
>in the SPARQL adapter. It seems to be working well. I've
included my changes
>below if you'd like to incorporate them into the
ActiveRDF code.
thanks for that. Would it maybe be possible for you to send
these changes 
in a diff file [1]? Using bzr, diffs are even easier to
generate [2].

>Scanning the SPARQL language spec, I can't find the
endpoint definition, so
>I'm not sure if POST is supported. Nevertheless, the
inability to perform
>lengthy SPARQL queries through GET seems to necessitate
the need for
>POST-based queries.
It's in the SPARQL protocol definition [3], not in the query
language.  
Until your email, I didn't even know you could use POSTs.

  -eyal

[1] http://laughingmeme.org/2004/02/18/how-to-make-a-pat
ch-file/
[2] http://blogs.gnome.org/jamesh/2007/07/31/bazaar-bundles/

[3] http://www.
w3.org/TR/rdf-sparql-protocol/
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf

Re: Using POST instead of GET for Sparql queries
user name
2007-10-01 04:46:55
On 10/01/07/10/07 11:35 +0200, Eyal Oren wrote:
> thanks for that. Would it maybe be possible for you to
send these changes 
> in a diff file [1]? Using bzr, diffs are even easier to
generate [2].
Actually, I now incorporated your changes manually already
so you can save 
the diff for the next time 

I'll release the updated SPARQL adapter gem shortly.

  -eyal
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf

[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )