[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

REST API status code?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 2

File: feature-reliable.png (209KB, 1000x600px) Image search: [Google]
feature-reliable.png
209KB, 1000x600px
Hello /g/,

I'm building a REST api using express and mongoose.
For now, my API is returning a simple json object like this with no http status:

 
{
success: true,
data: [dataarray]
}

or
 
{
success: false,
error: {errObject}
}


Would it be better to just set different status code to detect errors? So if a request have a 500 status, i'm just returning back the error object, if this is status code 200 i'm sure the data is there so i'm just returning the data array etc...

Any suggestions?
>>
>>58957107
wtf do you want ?
if you just want to know what the error is about just log full object with error info ?
or what is your problem ?
>>
>>58957107
{
success: true/false,
data: [stuff or empty if false],
error: int code, 0 no error, ...
}
>>
http://www.restapitutorial.com/httpstatuscodes.html
http://racksburg.com/choosing-an-http-status-code/
>>
File: funked.png (477KB, 600x626px) Image search: [Google]
funked.png
477KB, 600x626px
Yes use status code, 200 for success, 422 if object couldn't be updated
>>
>>58957275
This

On success
{
success: true, // can fairly easily be omitted, success = error == null
error: null,
data: [stuff]
}


On failure
{
success: false,
error: { someField: someValue },
data: null
}
>>
>>58957107
yes you are supposed to use http status codes to better express application state
same with http methods, refresh headers etc
don't just post everything, use put or patch to complete or update existing resources, use delete instead of posting to uri/delete
rely on http protocol as much as possible
Thread posts: 7
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.