ajax - Breeze.js: Handling empty results -


let's have detail page items: /items/{id}. user can of course try random id, if doesn't have access item, return detail page no data, not nice. i'd rather return 404 or 204 instead. however, breeze web api, i'm returning iqueryable, can't return error, , i'd have handle empty set on client. nicest way doing this? i'm thinking of checking if result empty , redirecting custom 404 page, wondering if there's better way?

thanks

when write service/web api controller method returns iqueryable, have made conscious decision http resource collection. collection may empty ... empty collection valid resource full collection. collection found , correct response 200, not 404.

if you're http request specific item (eg.., had endpoint designed return single object route ~/customers/:id), returning http response status 404 makes sense. can have both kinds of endpoints if wish. breeze doesn't force iqueryable. option. can have mix of both kinds of endpoints.

for me, larger concern possible confusion between data (the customer(s)) , ui (the page). web api isn't returning page; it's returning data.

i'm assuming you're building "single page application" has detail screen. indeed have decide should happen if navigates detail screen, try fetch entity screen id, , discover such entity not exist. have decide go.

that decision independent of http status code. can re-direct client-side screen safe location (e.g., list of customers) without worrying http status codes. http status codes part of http protocol communication on web. application's own client-side screen navigation isn't crossing web , there no need (and no point) adopting protocol.

you should fine detecting web api returned empty collection. there no embarrassment. http police not arrest you. re-direct appropriate.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -