Live data from Hacker News

REST Anti-Patterns (2008)

infoq.com

21–30 of 118 posts

Re: REST Anti-Patterns (2008)

#21

> Ignoring status codes My favorite is when everything returns a 200, but the response is something like: { status: "fail", error: "forbidden" } Sometimes they even include the 403 in the response, almost like the developer is giving you a giant middle finger.

This was a common workaround, so that customers don't get nervous, as some browsers showed an increasing number in a red circle at the top right. (i.e. the number of JavaScript errors)

Re: REST Anti-Patterns (2008)

#22
post #8

If API's are best represented via REST, then why aren't software API's in general RESTful (e.g. I dont POST triangles to my GPU)? The answer: SOME API's are best represented with REST, but most are not.

Because the concept of REST was specifically designed around HTTP, not to be some abstract interface between any 2 systems.

I agree but also have counter example, perhaps not yet as an interface for two systems. But let's start with this:

What if I can ask my OS to do things I normally do over some protocol like HTTP in a RESTful style? Create user, list directory, find the last login, tell me linux kernel version.

^ has been done as a separate monitoring tool like Osquery, but can't we make such protocol natively? I don't want to parse my command-line output if I can just speak in one human-readble, machine-friendly dialect.

Re: REST Anti-Patterns (2008)

#23

> Ignoring status codes My favorite is when everything returns a 200, but the response is something like: { status: "fail", error: "forbidden" } Sometimes they even include the 403 in the response, almost like the developer is giving you a giant middle finger.

omg I saw this once.

The status code was 200 but the HTTP body was literally "403: Forbidden". On an endpoint that was supposed to return XML .

I guess they just read the spec and assumed "the API returns a '403: Forbidden' " meant this.

Re: REST Anti-Patterns (2008)

#24

> Ignoring status codes My favorite is when everything returns a 200, but the response is something like: { status: "fail", error: "forbidden" } Sometimes they even include the 403 in the response, almost like the developer is giving you a giant middle finger.

[deleted]

Re: REST Anti-Patterns (2008)

#25

> Ignoring status codes My favorite is when everything returns a 200, but the response is something like: { status: "fail", error: "forbidden" } Sometimes they even include the 403 in the response, almost like the developer is giving you a giant middle finger.

omg I saw this once. The status code was 200 but the HTTP body was literally "403: Forbidden". On an endpoint that was supposed to return XML . I guess they just read the spec and assumed "the API returns a '403: Forbidden' " meant this.

I wish I only saw this once. This is my life. I integrate with 3rd party APIs for a living...what I've learned is that everyone's 'REST' API is terrible in one way or another.

Re: REST Anti-Patterns (2008)

#26

Missing anti pattern: consider URLs insecure, especially if for a web browser. Don't include customer details (name, email, account number, etc) or search queries (free text) unless you have determined the security settings on your logging, audit, proxies, .., all conform to data protection requirements that suggest they should be encrypted and only visible to necessary staff. If you expect pages to be bookmarked or…

> consider URLs insecure, especially if for a web browser.

A web site I used recently puts your session ID in the URL. If you log in, then alter the URL to remove the session ID, you appear logged out.

It gets even worse. Clicking the "Log out" button on the page simply removes the session ID from the URL. If you go back and reload the web page with the session ID in it again, you still appear logged in.

The page also doesn't use HSTS so is easily vulnerable to SSLStrip.

Re: REST Anti-Patterns (2008)

#27

> Ignoring status codes My favorite is when everything returns a 200, but the response is something like: { status: "fail", error: "forbidden" } Sometimes they even include the 403 in the response, almost like the developer is giving you a giant middle finger.

You can blame old browsers for this. In the old days if you returned a non 200 the browser could die in all sorts of interesting ways. Heaven forbid if you try and use any verb other than GET or PUSH, it probably turns the fan off your computer to try and start a fire or something.

>You can blame old browsers for this. In the old days if you returned a non 200 the browser could die in all sorts of interesting ways.

No, they really didn't. And I've started with Mosaic...

Re: REST Anti-Patterns (2008)

#28
post #18

Have we considered that these REST "anti-patterns" exist because REST is fundamentally inappropriate for what most people are trying to use it for? What if you can't shoehorn your functionality into the handful of REST verbs? What if none of the status codes make sense? What ever happened to plain old RPC? Have we stopped to consider that people tunnel things through POST or GET requests because it's easier and more…

Most things on the web are half-assed, and half-assed HTTP APIs enable rapid results (before the problems start). REST is not fundamentally inappropriate, it just needs a lot of careful design about domain objects, link relations, and media types. Generally, people are not very good at thoughtful design. It didn't help that REST began to trend as an idea right around the same time that intentionally schemaless JSON w…

>REST is not fundamentally inappropriate, it just needs a lot of careful design about domain objects, link relations, and media types. Generally, people are not very good at thoughtful design.

Especially if it's not worth the effort.

Re: REST Anti-Patterns (2008)

#29
post #9

Earlier quoted context omitted.

Much as I would like to agree with you, that war was already fought and lost in the early '00s. Port 80/443 were the two ports that couldn't ever be firewalled because web browsing depended on them, so everybody rushed to cram their RPC requests into some kind of HTTP-based protocol.

HTTP != REST though, as the article notes. There are other ways to use port 80/443 that neither violate HTTP nor go full REST - websocket being an (extreme) example. Even the HTTP monopoly is changing. There are lots of new protocols (HTTP2, QUIC, WebRTC) that work besides firewalls and things like ALPN gives a standardized way to tunnel new protocols over an encrypted connection.

>HTTP != REST though, as the article notes.

The article might note it, and Roy might insist on it, but nobody cares.

For all intents and purposes, what people call REST in practical use is RPC over HTTP with JSON responses.

Re: REST Anti-Patterns (2008)

#30
post #18

Have we considered that these REST "anti-patterns" exist because REST is fundamentally inappropriate for what most people are trying to use it for? What if you can't shoehorn your functionality into the handful of REST verbs? What if none of the status codes make sense? What ever happened to plain old RPC? Have we stopped to consider that people tunnel things through POST or GET requests because it's easier and more…

Most things on the web are half-assed, and half-assed HTTP APIs enable rapid results (before the problems start). REST is not fundamentally inappropriate, it just needs a lot of careful design about domain objects, link relations, and media types. Generally, people are not very good at thoughtful design. It didn't help that REST began to trend as an idea right around the same time that intentionally schemaless JSON w…

It helps that GraphQL has an actual spec, protocol, and defined schema and is intended to be shipped as a separate microservice that just implements your schema according to the spec.

REST is more "hodge podge of concepts" that you can hack on and pollute and misunderstand at will.

I guess nothing will stop people from making Frankenstein schemas or poorly performing resolvers but at least the consumption is mostly uniform?

Post reply on HN