Search code examples
apihttpresthttp-method

Best HTTP Method for Get or Create


I'm writing an HTTP based API, and I have a situation where the user specifies a resource, and if that resource doesn't yet exist the server creates it. It's basically built on top of Django's get_or_create method.

What would be the most idiomatic/correct HTTP method to use in this situation?

I'm suspecting that POST would be proper. However, I'm not entirety sure. Though it seems that GET would be incorrect seeing as it's not supposed to have any side-effects.


Solution

  • I would use GET for this. Repeated calls to this end point will return the same resource, so it's still Idempotent.