16 Matching Annotations
  1. Last 7 days
    1. "The basic principle behind REST status code conventions is that a status code must make the client aware of what is going on and what the server expects the client to do next"
    2. You can fulfill this principle by giving answers to the following questions:Is there a problem or not?If there is a problem, on which side is it? On the client or on the server side?If there is a problem, what should the client do?
    3. Now, assume your client attempts to access a resource that it MUST NOT access at all, for example, because it belongs to another user. What status code should your API return? Should it return a 403 or a 401 status code?You may be tempted to return a 403 status code anyway. But, actually, you can't suggest any missing permission because that client has no way to access that resource. So, the 403 status code gives no actual helpful information. You may think that returning a 401 status code makes sense in this case. After all, the resource belongs to another user, so the request should come from a different user.However, since that resource shouldn't be reached by the current client, the best option is to hide it.
    4. Let's explore a different case now. Assume, for example, that your client sends a request to modify a document and provides a valid access token to the API. However, that token doesn't include or imply any permission or scope that allows the client to perform the desired action.In this case, your API should respond with a 403 Forbidden status code. With this status code, your API tells the client that the credentials it provided (e.g., the access token) are valid, but it needs appropriate privileges to perform the requested action.
    1. The difference is what the server expects the client to do next.
    2. Send a 302 to your login-page

      That's typically what people do, isn't it.

      That answers the question "how do we best instruct the user agent to take the next step that is required". And maybe a redirect is in fact the best answer.

      See https://hyp.is/mDvXsHoxEeyHC0Ol9HE3CA/stackoverflow.com/questions/3297048/403-forbidden-vs-401-unauthorized-http-responses

    3. Checks are usually done in this order: 404 if resource is public and does not exist or 3xx redirection OTHERWISE: 401 if not logged-in or session expired 403 if user does not have permission to access resource (file, json, ...) 404 if resource does not exist or not willing to reveal anything, or 3xx redirection
    4. +----------------------- | RESOURCE EXISTS ? (if private it is often checked AFTER auth check) +----------------------- | | NO | v YES v +----------------------- 404 | IS LOGGED-IN ? (authenticated, aka user session) or +----------------------- 401 | | 403 NO | | YES 3xx v v 401 +----------------------- (404 no reveal) | CAN ACCESS RESOURCE ? (permission, authorized, ...) or +----------------------- redirect | | to login NO | | YES | | v v 403 OK 200, redirect, ... (or 404: no reveal) (or 404: resource does not exist if private) (or 3xx: redirection)
  2. May 2021
    1. The job of this function is to return a { status, headers, body } object representing the response, where status is an HTTP status code: 2xx — successful response (default is 200) 3xx — redirection (should be accompanied by a location header) 4xx — client error 5xx — server error
  3. Nov 2020
    1. All browers handle 302 incorrectly. Chrome 30, IE10. It became the de facto incorrect implementation; that cannot be changed because so many web-sites issue mistakenly issue 302. In fact ASP.net MVC incorrectly issues 302, depending on the fact that browsers handle it incorrectly.
  4. Aug 2020
    1. Yeah, so I believe what we want is.. If an action has no templates defined at all, AND it has no respond_to { ... } block, then it should do a 204 If an action has certain templates defined, AND it has no respond_to { ... } block, then it should do a 406 for formats with no templates If an action has a respond_to { ... } block, then it should do a 406 for formats not in the list
  5. Apr 2020
    1. “What other framework has integrated support for 786 TRY IT NOW ?”

      I couldn't find documentation of what this is referring to. Is it a custom HTTP status code?

      https://falcon.readthedocs.io/en/stable/api/status.html mentions

      HTTP status line, e.g. ‘748 Confounded by Ponies’. but not 786.

  6. Dec 2019
    1. I understand that GitHub uses "Not Found" where it means "Forbidden" in some circumstances to prevent inadvertently reveling the existence of a private repository. Requests that require authentication will return 404 Not Found, instead of 403 Forbidden, in some places. This is to prevent the accidental leakage of private repositories to unauthorized users. --GitHub This is a fairly common practice around the web, indeed it is defined: The 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists. --6.5.4. 404 Not Found, RFC 7231 HTTP/1.1 Semantics and Content (emphasis mine)
  7. Jun 2017