JimHawkins
JimHawkins

Reputation: 5000

RESTful web service, POST for data retrieving

I'm thinking about creating a REST API for an existing pure HTTP-based web service.

Until now, clients can send HTTP POST requests to the service for retrieving data. The HTTP bodies of these requests contain something like query parameters. It is a XML dialect. These queries can often have a size of more than 30 kB.

Also, encryption is required for queries. So, the query parameters can't be transfered by HTTP GET as a query string.

My question is: does it violate the REST principle "POST changes server state", if I use HTTP POST for retrieving data?

After every retrieving action (successful or not), a log-entry is added to a logging-table in a database.


Update

So, the query parameters can't be transfered by HTTP GET as a query string

As I've learned from the comments and the answer, the query string is encrypted. But it's not recommended to transfer security sensitive data within the query string.

Upvotes: 2

Views: 320

Answers (1)

Alex
Alex

Reputation: 38499

While it technically violates REST, if your query parameters are large, which it sounds like they are, then POST may be the only way to go. Also, not all clients support GET with body parameters.

ElasticSearch also allows POST queries:

Both HTTP GET and HTTP POST can be used to execute search with body. Since not all clients support GET with body, POST is allowed as well. https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html

As does Azure Search API
https://msdn.microsoft.com/en-gb/library/azure/dn798927.aspx

The point I'm trying to make is that while it goes against REST principals, sometimes rules are there to be broken.
You could always think of it as POSTing (creating) a query ;-)

As a side-note re: GET requests / query strings

The entire text of an HTTPS session is secured / encrypted by SSL.
This includes the query and the headers.
In that regard, a POST and a GET would be exactly the same.

Upvotes: 3

Related Questions