How i will return status code & message depend on condition in API?
[HttpGet("{id:int}")]
public ActionResult <VillaDTO> GetVilla(int id)
{
if (id == 0) {
return BadRequest(); //return 400
}
var villa = VillaStore.villasList.FirstOrDefault(u => u.Id == id);
if (villa == null) {
return NotFound(); //return 404 not found
}
return Ok(villa); //return 200 success
}
Here when user try to get data entering id. If user enter id zero(0)
then it’s called BadRequest
which return 400
. If user enter any id which is not exist in list then user will get 404
code which means data not found
. If data exist then user will get 200
code with success
message.
Excellent post. I absolutely appreciate this website. Continue the good work!
Pingback: RUAY เว็บหวยออนไลน์
Pingback: helen88
Pingback: รักษาสิว
Pingback: โบท็อกราคา
You’ve written terrific content on this topic, which goes to show how knowledgable you are on this subject. I happen to cover about Cosmetic Treatment on my personal blog QH8 and would appreciate some feedback. Thank you and keep posting good stuff!
Pingback: dark168
Pingback: funny videos
Pingback: nova8899 พนันออนไลน์ เว็บตรง