• Aatube@kbin.melroy.org
    link
    fedilink
    arrow-up
    3
    ·
    1 day 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
      7
      ·
      1 day 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” }

        • locuester@lemmy.zip
          link
          fedilink
          English
          arrow-up
          2
          ·
          edit-2
          1 hour ago

          A RESTful service is (usually as of today) a JSON API. They aren’t mutually exclusive things.

          There’s no black and white definition there.

          However, when someone is creating a RESTful service, they’re stating that they’ll be paying mind to HTTP Verbs and status codes as a fundamental part of their design.

          In the original image posted, that dev clearly wasn’t paying mind to the HTTP layer and as such a commenter called it just a “JSON API”, which is the catchall, ugly, Wild West, typical way of doing things (always return 200, errors are in the json).

          Once again tho, it’s not black and white. Others can and will disagree and want to be pedantic. I’ve been a professional dev for 35 years, devs love to argue abt this shit.

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

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