Distinguishing REST calls from normal browser access

This summarises how Metrici distinguishes between REST calls and normal browser-based HTML or file access.

  • If the URL includes the parameter method=rest, it is a REST call.
  • If the URL includes the method parameter and it is not "rest", it is not a REST call.
  • If the http method is PUT, PATCH or DELETE, it is a REST call.
  • If the accept header includes "html", "image", "css" or "javascript", it is not a REST call.
  • If the accept header includes "json" or "xml", it is a REST call.
  • If the referer header is populated, it is not a REST call.
  • If the URL has a file extension (the last part is not numeric), it is not a REST call, and the file is served.
  • If there is no user-agent header, it is a REST call.
  • If the user-agent header contains any of the values in the server-wide "htmlOnlyUserAgents" parameter, it is not a REST call. This is used to detect search engine crawlers such as Google.
  • Otherwise, it is a REST call.

To ensure the REST interface is called:

  • Don't set the accept header or user-agent header.
  • Don't use a file extension.

If you are making a REST call from a browser, you must force it to be a REST call, rather than retrieving the node rendered as HTML. You can do this by setting the accept header to "application/json" or "application/xml", depending on the expected return type, or by appending the query parameter method=rest.