user125498
user125498

Reputation: 25

REST principles - returning a simple response

I'm working with Django REST framework. By default, all the requests returns a JSON object containing the pagination (prev, next, count, results). This is useful in 90% of the cases where the user retrieves or creates info about something. However, there are a few resources which don't have to return anything but rather a confirmation that everything went smoothly - for example, imagine a resource which is just a heartbeat request ("ping") to maintain the session active.

Would it be okay to return a simple response, such as {result: true} (without any pagination like the rest of resources have) or would this be an eventual violation of the REST principles?

Upvotes: 0

Views: 94

Answers (3)

inf3rno
inf3rno

Reputation: 26139

Pagination should be solved with range headers or hyperlinks. You don't need the body in empty responses, just the status header.

Upvotes: 0

Pedro Werneck
Pedro Werneck

Reputation: 41898

If all you want is to know if the URI is fully serviceable, disregarding the body completely, you should simply support a HEAD request instead of GET.

Upvotes: 1

user1907906
user1907906

Reputation:

Yes, ouf course such a response to a ping request is OK. Pagination is something only suitable for a collection that can be paged. Paging An unique resource that is not a collection does not make sense.

For the ping request you could even leave the response body empty.

Request:

GET /ping

Response:

200 OK
Content-Length: 0

Upvotes: 0

Related Questions