Web Technologies

REST API best practices: URLs, methods and status codes

REST API best practices: noun URLs, HTTP methods as verbs, accurate status codes, stateless requests, versioning, input validation and clear documentation.

  • 8 min read
  • 5 questions
  • +35 XP
Transcript

REST API Best Practices, explained by cats. Kitty builds a REST API. Other apps will use it. So it needs to behave nicely. Kitty should follow industry best practices. Kitty finds some common rules. First rule: Resources are nouns. They are things.

Not actions. In this example. Cats are the thing. and URLs name the thing. Second: HTTP methods are verbs. They say what you’re doing. For example, use GET to fetch tuna. POST to create tuna. PUT or PATCH to update tuna.

DELETE to remove tuna. Same URL. Different verb. Clear intent. Third: Use proper status codes. 200 means success. 201 means created. 400 means bad request. 404 means not found. No guessing. No vibes. Fourth: Keep it stateless. Every request stands alone.

All info included. No memory between naps. Fifth: Version your API. like this. So new tricks don’t break old cats. Sixth: Validate and sanitize input. Never trust random cats. Especially ones yelling in JSON. Finally: Document everything. So other cats know how to talk to your API.

Good REST APIs are predictable. Resources are nouns. HTTP methods are verbs. Everything has a place. That’s REST done right. Now Kitty will take a nap and rest.