loopback icon indicating copy to clipboard operation
loopback copied to clipboard

HTTP REST inconsistency: create should return HTTP 201

Open fabien opened this issue 12 years ago • 10 comments

Apparently, POST /api/things returns HTTP 200 - however, 201 is the right code.

fabien avatar Jul 02 '14 10:07 fabien

I agree that POST for creation should return HTTP 201. In addition, there should be a 'Location' header with a URL points to the instance being created, for example:

Location: http://localhost:3000/api/things/1

Since it will be a breaking change, we'll probably have to fix it in 2.x stream.

raymondfeng avatar Jul 07 '14 20:07 raymondfeng

Hey guys,

Any news on this issue?

I could probably provide a PR for it but I would need some pointers on where the changes should be made.

gcirne avatar Aug 04 '14 21:08 gcirne

up!

albertoleal avatar Aug 14 '14 17:08 albertoleal

Should be so: POST /api/things returns HTTP 201 PUT /api/things/:id returns HTTP 200 GET /api/things/:id returns HTTP 200 GET /api/things returns HTTP 200 or 206 if need "Range" DELETE /api/things/:id returns HTTP 204

zbitname avatar Aug 14 '14 17:08 zbitname

+1

wpjunior avatar Aug 14 '14 21:08 wpjunior

Any update on this issue? Almost a year now for something I would deem critical to REST patterns and service integrators.

wrensburg avatar May 07 '15 17:05 wrensburg

:+1:

seriousben avatar May 07 '15 17:05 seriousben

Having switched to loopback for my webservice layer I'm having to change all my tests and checks because of this inconsistency.

slyadams avatar Feb 24 '16 17:02 slyadams

@zbitname, PUT also might and should return 201 if the request led to instance creation. 200 for rewriting existing one only. DELETE may return 200 in case you decide to design your API in way DELETE to return deleted item in response.

brawaga avatar May 15 '17 02:05 brawaga

LoopBack 3 is in Maintenance LTS mode, only critical bugs and critical security fixes will be provided. We are tracking this request for LoopBack 4 here: https://github.com/strongloop/loopback-next/issues/788

bajtos avatar Mar 10 '20 14:03 bajtos