GALAglobal / TAPICC-API-implementation

TAPICC API implementation using node.js framework sails.js
Other
6 stars 1 forks source link

Return for creation #54

Closed ysavourel closed 5 years ago

ysavourel commented 6 years ago

Usually REST APIs return 201 (Created) and the created object when one create a new resource. Currently the API returns 200 with the created job, task, asset or webhook. We should return 201.

Alino commented 6 years ago

I am not sure about this, the petstore swagger example is returning code 200 and the response is the object created.

Also I have reviewed this stackoverflow thread Where I would agree with this kind of answer

200 when an object is created and returned 201 when an object is created but only its reference is returned (such as an ID or a link)

So I would say 201 is useful if your created object is too big to be in the response, and you return only location instead, for the sake of bandwidth or performance optimisation.

ysavourel commented 6 years ago

It seems the stackoverflow discussion is about how to indicate the resource(s) created, rather than choosing between 200 and 201. And for that we should certainly use the Location entry header.

There is certainly nothing particularly wrong with 200. But it seems to me that if there is an HTTP response code specifically designated to indicate a resource has been created, we should use it. Nothing in its definition say it should be used when the resource is not attached (and 200 when the resource is attached).

201 after creation is what some recommend:

And it is what some TMS already use:

Alino commented 5 years ago

updated in swagger https://github.com/GALAglobal/TAPICC-API-implementation/commit/17048737e981975ee704c94ddd4eac191209ded9