SB2055
SB2055

Reputation: 12912

GET request with data in body

I'm implementing an API endpoint that serves data but makes no modifications to data - it's something along the lines of "GET all items that match this list of filters", where a filter could be something like "ID > 200" or "propertyA != null".

In actual implementation, I have to send an array to the endpoint, specifying a bunch of resources on a per-id basis to GET back to the client. Something like

GET api/tickets

{
    ids: [1, 3, 5, 7, 9],
    filter: "on-sale"
}

From what I understand, a Restfully implemented api would not use GET for this kind of request as it's expected that only the id of the target resource is specified in the url, with no contents in the body.

Though I hate to think I would have to hamfist this thing into a PUT or POST request.

What's the right thing to do here?

Upvotes: 0

Views: 114

Answers (1)

Darrel Miller
Darrel Miller

Reputation: 142242

HTTP does not allow you to sending meaningful information in the GET body. You can however send lists in the request URI.

This URI is perfectly valid.

GET /tickets?ids=1,3,5,7,9&filter=on-sale

Upvotes: 1

Related Questions