top | item 36933787

(no title)

wak90 | 2 years ago

I remember getting an interview question wrong when I said "yeah a get is supposed to just respond with data but you're writing it, you can make it do whatever you want"

discuss

order

charrondev|2 years ago

I mean most GET requests have at least one side effect: one or more cache writes.

I’ve also implemented some GET endpoints that are a GET but have a side effect of marking something as read. (Normally as a variant to an existing endpoint for sessioned user).

I would expect at a minimum though if you are doing writes during a GET it should be idempotent.

kiitos|2 years ago

Well, caching a response to a GET request is always going to be subject to variables like Etag and other hashes of the request, time limits, etc. which all ensure that responses, even old responses, are never _wrong_, they're at worst _stale_.

That's different, and safer, than something like a "read" bit on an entity, presumably tracked in an application data layer. I don't think you can mark something as "read" in your application from a GET request. Even if your server sees the response to that GET request as successful, it doesn't necessarily mean that the requesting client actually successfully received the response. As one of infinitely many possible counter-examples, consider a middlebox between a client and your server, where one client request to the server may generate N requests from the middlebox to the server.

eddd-ddde|2 years ago

During any serious side effects with a GET is a bad idea because of xsrf anyways