BEST Practices in REST

B Wood
B Wood
Nov 5 · 2 min read

What does it mean to be RESTful?

REpresentational State Transfer is a software architectural design pattern that guides our web development. The client interacts with the server through a set of systematic and predefined operations, most commonly HTTP methods. In REST, these operations are stateless, meaning the server’s response to input from the client is independent of any prior state. The data passed in becomes paired to the request itself.

Follow below best practices to ensure your web API is as RESTful as possible!

  1. Nouns over verbs
  2. Spinal-case
  3. HATEOAS
  4. Status Codes

Nouns over verbs

Resources should be described with pluralized, lowercase nouns to be RESTful rather than verbs. Let’s see why with an example.

Say we define below APIs in a simple Department store model:

  • /viewdepartment
  • /editdepartment
  • /updatedepartment
  • /deletedepartment

This naming pattern would become very difficult to maintain as functionality, and subsequently count, increases.

Instead, leverage HTTP methods to make things more uniform:

Much cleaner!

Spinal-case

Another naming convention in REST is to use hyphens (spinal-case) rather than underscores (snake_case). The reason for this is that an underscore can be partially obscured or difficult to see in some browsers or screens. Avoid this with hyphens!

HATEOAS

aka Hypermedia as the Engine of Application State, is an important component of REST. This is the concept that the client shouldn’t need any prior knowledge of your web app to interact with it effortlessly and successfully. Responses in a RESTful API describe to the client how it should be used, specifically through Hypermedia. An easy example is the use of links to guide the user, like an “add to cart” link.

Status Codes

Help out the user with errors as much as possible by indicating the correct status code. Here’s a table of some of the most common status codes:

Source: https://documentation.commvault.com/commvault/v11_sp14/article?p=45599.htm

REST IS THE BEST!

zzzzzzzzzzzz

B Wood

Written by

B Wood

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade