Sv443-Network / JokeAPI

REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
https://v2.jokeapi.dev
MIT License
253 stars 47 forks source link

This API is not RESTful #529

Closed cellularmitosis closed 1 month ago

cellularmitosis commented 1 month ago

When I request an intentionally bogus URL:

curl -v https://v2.jokeapi.dev/joke/Anyzzz

Instead of a 404, I get a 200 back (or should I call that a 106?):

{
    "error": true,
    "internalError": false,
    "code": 106,
    "message": "No matching joke found",
    "causedBy": [
        "No jokes were found that match your provided filter(s)."
    ],
    "additionalInfo": "The specified category/ies is/are invalid. Got: \"anyzzz\" but possible categories are: \"Any, Misc, Programming, Dark, Pun, Spooky, Christmas\" (case insensitive).",
    "timestamp": 1729482966153
}

It appears this API eschews HTTP and instead implements a custom protocol on top of HTTP.

For example, the standard way of indicating an internal error is to return a 500. However, it appears the API would instead return a 200 of the form:

{
    "error": true,
    "internalError": true,
    ....
}

This is a bummer, because everyone's existing knowledge, frameworks and tooling around handling REST APIs is now useless.

cellularmitosis commented 1 month ago

Sorry for venting my frustration.

Sv443 commented 1 month ago

No I get your frustration, but the API does correctly implement those status codes.
If you're getting a 200 on errors, then that's a bug.

Sv443 commented 1 month ago

Just verified it and yes, that's a bug. It should definitely reply with a 400 on this one:

image

Sv443 commented 1 month ago

Alright, bug is fixed now. If you didn't open this issue I probably would've never known so thanks!