REST architecture says that a resources state also should get a URL.
I am making a small application with very large queries. I would like to generate URLs with each query, but the queries are often larger than the URL character limit. I tried using URL shorteners but my URLss are too big even for them.
A lot of people online are suggesting using POST, but that is not idempotent. I really do not want to limit my query length and URLs should be able to identify an infinite amount of resources.
Is there a RESTful way to get around having very large URLs that does not involve POST requests?
Lutz Horn have answered it really well. But there is a good possibility that client might not be wishing to make three api calls - one to create a query response, second to get it, third to delete it.
If you are sure that your query length would remain less than 8 KB(which is the limit for get query length for most webservers), go ahead with GET request. Besides, if you are not interested in caching, use post there is nothing wrong with ignoring REST once in a while if you are well aware of the consequences.
To model this in a RESFtul way consider queries to be resources. They can be created, retrieved, and eventually deleted.
The client makes a
POST
request to aqueries
resource with the query details in the request body.This creates a new query resource. The server will respond:
The path segment
D560EC80-1006-11E5-80F6-75919330F945
will be an ID generated by the server for this specific query.Then the client requests the state of this query resource.
The server responds with the query result.
Later, the client can delete the query.
Or the sever can automatically delete the query after some time.