• Slotos@feddit.nl
    link
    fedilink
    arrow-up
    11
    arrow-down
    1
    ·
    10 hours ago

    JSON API almost always means “not REST”. In other words, it works as intended.

      • Slotos@feddit.nl
        link
        fedilink
        arrow-up
        1
        ·
        2 hours ago

        However you like, REST doesn’t dictate anything there. Just be consistent and use hypermedia.

        JSON APIs almost never follow REST because they almost never use JSON as hypertext. Worse, no complete stable hypertext JSON standard exists. There’s JSON-HAL, but it lacks a way to represent resource templates (think HTML’s <form>).

        Therefore, with JSON APIs ignoring one of the most basic idea behind REST, why would anyone expect them to follow another idea of REST - consistency?

        REST is a deceptively simple concept. Any time you build an HTML website a human can navigate without consulting documentation, you’re doing it better than vast majority of swagger documented corporate APIs.

      • tempest@lemmy.ca
        link
        fedilink
        arrow-up
        3
        ·
        7 hours ago

        The argument probably goes something like " if you adhere strictly to REST the error codes are all you need" and then metadata can be sent in response headers.

        • Aatube@kbin.melroy.org
          link
          fedilink
          arrow-up
          2
          ·
          7 hours ago

          how should a REST API respond to the client sending a URL the ends in a string instead of a numeric ID? like api.social/users/ceeforayteen instead of api.socail/users/11037

          • locuester@lemmy.zip
            link
            fedilink
            English
            arrow-up
            4
            ·
            6 hours ago

            I would do a 400 (Bad Request). Then, with varying amounts of detail depending on the scale of the project and the framework capability, the response body would be something like: { “error”:true, “reason”: “validation”, “detail”: “user id should be numeric” }

          • tempest@lemmy.ca
            link
            fedilink
            arrow-up
            2
            ·
            6 hours ago

            Depends on the verb and the application. If the string is valid 200, if it isn’t 400, 404.