squirrelworks

RESTful API Design Guide

1. Resource-Oriented Design (Nouns, Not Verbs)

Acorn

The Gold Rule: In REST, the URL identifies the resource, while the HTTP method identifies the action. Never put verbs in your URIs.

To create a truly RESTful interface, your endpoints should always be named after the resources they represent. Use plural nouns to keep the API intuitive. For example, instead of /getUsers (which is an RPC style), use /users. This allows a single endpoint to handle multiple actions based on the HTTP verb used, such as fetching a list or creating a new entry.

The Incorrect Way (RPC)

  • /getAllOrders
  • /updateOrder?id=5
  • /deleteOrder/10

The RESTful Way

  • GET /orders
  • PUT /orders/5
  • DELETE /orders/10

2. Logical Sub-Resources

When resources are related, your URL structure should reflect that hierarchy. This makes the API self-documenting and easy for developers to navigate without referring back to documentation constantly.

If you want to fetch all comments for a specific blog post, the URI should flow from the parent to the child: /posts/001/comments. This clearly indicates that the comments are scoped to that specific post. Avoid going more than two or three levels deep (e.g., /users/1/posts/5/comments/10/author), as this makes the URI overly complex and difficult to maintain.


3. Filtering, Sorting, and Pagination

A common mistake is creating unique endpoints for different views of the same data (e.g., /getActiveUsers). In REST, you should use the base resource and modify the result using Query Parameters.

Query Parameter Examples:
  • Filtering: GET /users?status=active
  • Sorting: GET /products?sort=price_desc
  • Pagination: GET /orders?page=2&limit=50

By keeping the base URI clean, you allow the client to define exactly what data it needs. This reduces the "Information Density" overhead on the server and makes the API much more flexible for different frontend requirements, such as mobile apps vs. desktop dashboards.


4. HTTP Status Code Mapping

Proper REST design uses the built-in "language" of the web to communicate results. Never return a 200 OK if an error occurred.

Method Standard Path Success Code Technical Result
GET /resources 200 OK Returns a list or single object.
POST /resources 201 Created Creates a new record.
PUT /resources/id 200 OK Updates an existing record entirely.
PATCH /resources/id 200 OK Updates specific fields only.
DELETE /resources/id 204 No Content Removes the record successfully.
ANY Invalid Path 404 Not Found The URI does not exist.
ANY Auth Failure 401 Unauthorized Client lacks valid credentials.

5. Versioning for Durability

As your Squirrelworks projects grow, your data structures will inevitably change. To avoid breaking existing clients (like older versions of your mobile app or external integrations), you must version your API from day one.

The industry standard is to include the version in the URL path: /v1/users. This provides a clear "Contract" between the server and the client. When you need to make a "breaking change" (like renaming a JSON field), you deploy /v2/, allowing legacy clients to continue functioning on the v1 endpoint until they are ready to migrate. This maintains the "High Availability" state we strive for in enterprise-grade architecture.



Accessibility
 --overview

Agile
 --DevOps overview
 --Principles

API
 --REST best practices
 --REST demo
 --REST vs RPC
 --Wikipedia API

Blockchain
 --overview

Cloud
 --AWS overview

CSS/HTML
 --Bootstrap carousel
 --Grid demo
 --markdown demo

Electricity
 --fundamentals

Encoding
 --Overview

Ergonomics
 --Desk configuration
 --Device fleet
 --Input device array
 --keystroke mechanics
 --Phones & RSI

ERP
 --Anthology overview
 --Ellucian Banner
 --Higher Ed ERP Simulation Lab
 --PeopleSoft Campus Solutions
 --PESC standards
 --Slate data model

Git
 --syntax overview
 --troubleshooting libcrypto

Hardware
 --Device fleet
 --Homelab diagram

Java
 --Fundamentals

Javascript
 --Advanced Interaction: jQuery & UI Frameworks
 --input prompt demo
 --misc demo
 --Time and Date functions
 --Vue demo

Linux
 --grep demo
 --HCI and Proxmox
 --Proxmox install
 --xammp ftp server

Mail flow
 --DKIM, SPF, DMARC
 --MAPI

Microsoft
 --AZ-800: Administering Windows Server Hybrid Core Infrastructure
 --BAT scripting
 --Group Policy
 --IIS
 --robocopy
 --Server 2022 setup - Virtualbox

Misc
 --Applications
 --regex
 --Resources
 --Sustainable Computing
 --Terminology
 --The Humility Protocol: Reality Over Reputation
 --The Jordan Framework: Engineering a Competitive Edge
 --Tribute to Computer Scientists

Networks
 --BGP Peering & Security Hardening Lab
 --CCNA Lammle Study Guide
 --Cisco 1921/K9 router
 --routing protocols
 --throughput calculations

PHP/SQL
 --Cookies
 --database interaction
 --demo, OSI Layers quiz
 --Foreign key constraint demo
 --fundamentals
 --MySQL and PHPmyAdmin setup
 --pagination
 --security
 --session variables
 --SQL fundamentals
 --structures
 --Tables display

Python
 --fundamentals

Security
 --Overview- GRC (Governance, Risk, and Compliance)
 --Security Blog
 --SSH fundamentals

Serialization
 --JSON demo
 --YAML demo