promotably / api

API service
Eclipse Public License 1.0
0 stars 1 forks source link

201 created responses should return the newly created entity #131

Closed tomsouthall-zz closed 9 years ago

tomsouthall-zz commented 9 years ago

Currently, if say I successfully create an offer via a POST to /api/v1/offers, I receive a 201 Created response. The response text however is empty.

I am in a situation where I need to know the offer-id of a newly created offer without having to do a subsequent GET to retrieve it.

In my mind, all 201 responses should return the newly created entity.

If this is tricky for any reason, I particularly need /offers right now.

tomsouthall-zz commented 9 years ago

Oh actually /promos too. Need both.

smnirven commented 9 years ago

@tomsouthall do you need the whole entity or will just the id suffice?

tomsouthall-zz commented 9 years ago

@smnirven the whole entity - it's the way backbone's sync works.

smnirven commented 9 years ago

@tomsouthall can you check this out now?

tomsouthall-zz commented 9 years ago

@smnirven Thanks very much. Both end-points confirmed working.

tomsouthall-zz commented 9 years ago

@smnirven Reopening. Working for POST. Needs to work for PUT too.

smnirven commented 9 years ago

@t2 FYI the response status code on updates will change from 204 to 200. You don't want to know how long I was trying to figure out why the body was always nil, even though I was adding the updated promo in the handler. Turns out if you specify a status 204 (No Content), ring ignores what you set in the body and makes it nil.

smnirven commented 9 years ago

@tomsouthall okay, give this another shot. Let me know if anything's not copacetic

tomsouthall-zz commented 9 years ago

@smnirven The structure of the offer in the response differs between POST and PUT. For instance in POST, presentation is an object whereas in PUT presentation fields are flattened out. I'm expecting the object.

tomsouthall-zz commented 9 years ago

(and nice use of copacetic)

smnirven commented 9 years ago

@tomsouthall okay, one more time

tomsouthall-zz commented 9 years ago

@smnirven Looking good now! Cheers.

tomsouthall-zz commented 9 years ago

@smnirven I spoke too soon. This one doesn't actually affect anything yet, but it's still wrong so should be fixed.

I tried doing a PUT to /offers. I was adding a condition to the offer, and the condition seemed to be saved successfully. However the condition was not included in the response.

smnirven commented 9 years ago

now what

smnirven commented 9 years ago

god this bug won't die

tomsouthall-zz commented 9 years ago

Yeah sorry.

tomsouthall-zz commented 9 years ago

@smnirven I'm baaaack!!

If I PUT a condition to /offers, the condition is returned in the response. Correct.

If I POST a condition to /offers, the condition is NOT returned in the response. Bad!

cURL:

curl 'http://localhost:8282/api/v1/offers' -H 'Pragma: no-cache' -H 'Origin: http://localhost:8282' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,fr;q=0.6' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_102) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json, text/javascript, /_; q=0.01' -H 'Cache-Control: no-cache' -H 'X-Requested-With: XMLHttpRequest' -H 'Cookie: promotably-session=9f29f071-b91d-4f94-aa70-bee816e4ed2a; promotably=b2714a1c-5e08-4f6e-9afb-5ad9ab35930a; promotably-user=%7B%22user-id%22%3A%22b71e2361-2750-4cd0-bcd4-eb2db158244c%22%7D; __apiauth=cD73YIz3BTFFi%2BHohbQyeS3CBIYoblv1qTX%2FPzfYLi0CptDVHzK5Zottw%2BTfJ9wKB3gMR2r0WUlnPoL1F1yPTA%3D%3D; _gat=1; _ga=GA1.1.79999154.1426216891' -H 'Connection: keep-alive' -H 'Referer: http://localhost:8282/offers/create' --data-binary $'{"conditions":[{"type":"product-views","period-in-days":"60","product-views":"5"}],"reward":{"type":"promo","promo-id":"3a7a7852-4446-4317-80ca-f571093e4a78"},"presentation":{"type":"lightbox","page":"any","display-text":"Test","html":"<div class=\"promotably-theme\">\n <a class=\"promotably-close\">\xd7\n <p class=\"promotably-offer-text\">Test

\n

\n Use code: <span class=\"promotably-promo-code\">\n

\n <p class=\"promotably-expiry\" style=\"display: none;\">\n Expires in: <span class=\"promotably-countdown\">\n

\n
","css":"div.promotably-theme {\n position: relative;\n width: 500px;\n padding: 20px;\n background: #fff;\n line-height: 1.3em;\n}\ndiv.promotably-theme p {\n margin-top: 10px;\n}\ndiv.promotably-theme p.promotably-offer-text {\n margin: 0;\n}\ndiv.promotably-theme a.promotably-close {\n position: absolute;\n top: 0;\n right: 5px;\n font-size: 18px;\n display: block;\n text-decoration: none;\n color: #aaa;\n}\ndiv.promotably-theme a.promotably-close:hover {\n text-decoration: none;\n color: #000;\n}\n@media (min-width: 420px) and (max-width: 620px) {\n div.promotably-theme {\n width: 400px;\n }\n}\n@media (min-width: 320px) and (max-width: 420px) {\n div.promotably-theme {\n width: 300px;\n }\n}\n","theme":"simple-box"},"active":false,"code":"TEST2","name":"test2","site-id":"90a4db1c-924e-459c-916a-a11ebff804db"}' --compressed

smnirven commented 9 years ago

Heh -- okay. I fix

tomsouthall-zz commented 9 years ago

I see conditions :+1: Thanks.

But the bug that will never die lives on. The site-id in both the POST and PUT responses is an int and not a uuid. I think that might be the last thing.

tomsouthall-zz commented 9 years ago

Hm promo responses do not return a site-id at all. That probably doesn't matter for now as I don't use it anyway.

BUT... like offers the POST returns zero conditions (PUT is okay).