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 a queries
resource with the query details in the request body.
POST /queries
Content-Type: application/json
{
"condition1":
{
"on": "field1",
"comparison": "equals",
"value": 42
},
"condition2":
{
"on": "field2",
"comparison": "like",
"value": "foo%"
}
}
This creates a new query resource. The server will respond:
201 Created
Location: /queries/D560EC80-1006-11E5-80F6-75919330F945
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.
GET /queries/D560EC80-1006-11E5-80F6-75919330F945
The server responds with the query result.
200 OK
Content-Type: application/json
{
"id": "D560EC80-1006-11E5-80F6-75919330F945",
"querydetails":
{
"condition1":
{
"on": "field1",
"comparison": "equals",
"value": 42
},
"condition2":
{
"on": "field2",
"comparison": "like",
"value": "foo%"
}
},
"result":
{
"length": 12,
"results":
[
{
// details about the first hit
},
// more hits
]
}
}
Later, the client can delete the query.
DELETE /queries/D560EC80-1006-11E5-80F6-75919330F945
Or the sever can automatically delete the query after some time.