0

I have a method in Web API.

    [HttpGet]
    [HandleException("Unable to get Sections")]
    [Route("Sections")]
    public IHttpActionResult Sections()
    {
        var data = directoryDataService.Sections(1);
        if (data != null && data.Count > 0)
        {
            response.Data = data;
            return new Success(Request, "Sections Retrieved Successfully", response);
        }
        return new Error(Request, "No Sections Found");
    }

I have a doubt on the status code that I m return as a response. Currently if list of sections is available means returns "200" with data. If no sections available means, That is count of section is 0 means returns "400".

Is it right? Or I want to give 200 itself if count is 0.

SharmaPattar
  • 2,472
  • 3
  • 21
  • 23
  • Seeing as it is a `GET`, you would expect a 200 even if the `count == 0`. Only throw errors when something actually went wrong. Handle the `count ==0` in your calling code. – wjvander Dec 08 '15 at 09:48
  • 1
    In our current project we use `204 NoContent` for such cases. It means thet the server successfully processed the request, but is not returning any content. And I think it will be more proper than status code 400. Also in some cases we used `404 Not Found` – Roman Marusyk Dec 08 '15 at 10:02
  • 1
    http://www.restapitutorial.com/httpstatuscodes.html – Amit Kumar Ghosh Dec 08 '15 at 10:05

0 Answers0