How to be RESTful with long URLs?

The REST architecture says that the state of the resources must also get the URL.

I am making a small application with very large requests. I would like to generate URLs with every request, but requests are often more than the limit of the URL character. I tried using urls but my urls are too big even for them.

Many people on the Internet suggest using POST, but this is not idempotent. I really don't want to limit the length of the request, and the URLs should be able to identify an infinite amount of resources.

Is there a RESTful way to handle very large URLs that are not related to POST requests?

+4
source share
2 answers

RESFtul, . , .

POST queries .

POST /queries
Content-Type: application/json

{
  "condition1":
  {
    "on": "field1",
    "comparison": "equals",
    "value": 42
  },
  "condition2":
  {
    "on": "field2",
    "comparison": "like",
    "value": "foo%"
  }
}

. :

201 Created
Location: /queries/D560EC80-1006-11E5-80F6-75919330F945

D560EC80-1006-11E5-80F6-75919330F945 , .

.

GET /queries/D560EC80-1006-11E5-80F6-75919330F945

.

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
    ]
  }
}

.

DELETE /queries/D560EC80-1006-11E5-80F6-75919330F945

.

+3

. , api - , , .

, 8 ( -), GET. , , , , REST , .

0

All Articles