Hello folks,
I'm using Node.js, Sequalize and MySQL. I also heavily use Websockets.
I'm implementing a new REST Api, and I'm trying to learn about all the best practices I am potentially missing out. Recently, I've learnt about the following:
Idempotency. I was always trying to create APIs which can receive a route action twice and return the same thing. PUT /thing, PUT /thing should return 200 in both cases, for the situation when the client had lost the connection midway through the request and the user had to click again (or the client retried by itself, potentially). GETs are idempotent by default really. DELETEs should be idempotent too, really. POSTs are better to avoid, I think.
Eventual Consistency. Had a lot of trouble with this one. Apparently creating a row and then immediately reading it might return a null result, because the row hasn't propagated to all replicas. Oops. I guess I need to get everything I need with whatever the database returns from model.create and make do with that.
What are the other good practices I might be missing out on that gonna bite me in the future?
Cheers.
Top comments (0)