-2

In my MySQL database, I have a table named Messages which is having 4 rows , with unique message ID as 1,2,3,4.

When using REST Api I am accessing collection resource:

http://localhost:8080/messenger/webapi/messages

I am getting all the message entries as JSON , which is expected; Please find below :

[
    {
        "author": "Vineet",
        "creation": "09/12/2017",
        "id": 1,
        "message": "Message1"
    },
    {
        "author": "Puneet",
        "creation": "09/12/2017",
        "id": 2,
        "message": "Message2"
    },
    {
        "author": "Dad",
        "creation": "09/12/2017",
        "id": 3,
        "message": "Message3"
    },
    {
        "author": "Mom",
        "creation": "09/12/2017",
        "id": 4,
        "message": "Message4"
    }
]

When using REST Api I am accessing the individual resource:

http://localhost:8080/messenger/webapi/messages/1 or http://localhost:8080/messenger/webapi/messages/2 or http://localhost:8080/messenger/webapi/messages/3 or http://localhost:8080/messenger/webapi/messages/4

I am getting the expected response for every single resource e.g. for 1

{
        "author": "Vineet",
        "creation": "09/12/2017",
        "id": 1,
        "message": "Message1"
 }

Problem : When I am trying to access url :

http://localhost:8080/messenger/webapi/messages/9 , where 9 is a resource that never exists in database.

I am getting a blank page or the last loaded page. and The HTTP Code coming is : 204.

When "9" id is not present , why is not there 404 message ? Why 204 ?

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
  • What framework are you running your REST API in? If it's Jersey, [this question](https://stackoverflow.com/questions/2195639/) might help. – Luke Woodward Dec 09 '17 at 20:55
  • @LukeWoodward Thanks for helping with that post. But I did not get my answer. When resource does not exists, then where does it look up and bring null value ? It should be 404 error but 204 is coming. – vineettalashi Dec 10 '17 at 09:45
  • You haven't answered my question! Are you using Jersey for your REST API? Or are you using something else, and if so, what? – Luke Woodward Dec 10 '17 at 13:01
  • I am sorry. Yes I am using Jersey. @LukeWoodward – vineettalashi Dec 10 '17 at 13:32

1 Answers1

0

The route is correct and only the paramerter which you have provided is wrong so there is no way you will get a 404 which is page not found but the request has hit service so it a successful service hit

I hope you can handle the error in exception handling.

Kannan
  • 1
  • 4
  • But the resource I am hitting does not exists. I am still confused.Anyway, could you please help in exception handling code regarding Error 204.Thanks for your help. – vineettalashi Dec 12 '17 at 10:53