1

Say there is an api call /super-api/calendar/date/events. The resource "events" is created only when you add one or more events to a particular date in the calendar. Currently, the api returns 404 when there are no events in the calendar. My thought it that the api should return zero events or something like that instead of 404. But, I am not 100% sure. The reason - 404 could be generated because the url is wrong or the resource name changed. Please advise.

Edit - I believe that the underlying code should be changed to generate "events" resource for every date in the calendar instead of waiting to do that when a user adds an event to a date.

Related question - REST API 404: Bad URI, or Missing Resource?

Unfortunately, the related question does not answer my specific scenario. Hence, I posted this as a new question. I would actually like to post this as a comment instead, but I cant because I am new here.

Community
  • 1
  • 1
code.chimp
  • 11
  • 3
  • 1
    I would return a 0 for 0 events vs 404 error in that case. 404 would be more for they have the wrong url vs a 0 return value. – Danny Mar 14 '17 at 00:34
  • 10.4.5 404 Not Found The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable. – bichito Mar 14 '17 at 01:01
  • This is from w3.org. I would think that since the resource is not there the api should return 404 – bichito Mar 14 '17 at 01:02
  • If you are doing PURE REST implementation then you should return 404. Be it wrong uri or resource (event) doesn't exist. In any case it should be 404. – Pankaj Kapare Mar 14 '17 at 01:12
  • The resource is there. It's an empty bag of events. – alayor Mar 14 '17 at 01:32
  • @alayor - I am not sure. It seems that the resource is not there until an event is added to a date. – code.chimp Mar 14 '17 at 01:49

1 Answers1

1

You're right, you should return an empty list instead of 404 error (you could return 204 though). You could return 404 in queries like this one in case there is no event with id 2.

/super-api/calendar/date/events/2

alayor
  • 4,537
  • 6
  • 27
  • 47