Skip to content

Instantly share code, notes, and snippets.

@Silverbullet069
Last active December 31, 2023 12:27
Show Gist options
  • Save Silverbullet069/ddae51d0b29d84cac2637204b587155c to your computer and use it in GitHub Desktop.
Save Silverbullet069/ddae51d0b29d84cac2637204b587155c to your computer and use it in GitHub Desktop.
[Web best practices] Some cool things I note when I'm learning on Internet

Best practice for RESTful API design

Parameters

  • Path Params: identify a specific resource of resources
  • Query Params: soft/filter resources

Example: RESTful API endpoints for an entity called Car

Path params

  • GET /cars
  • GET /cars/:id
  • POST /cars
  • PUT /cars/:id
  • DELETE /cars/:id

Query params: filter the cars by color

color is not a resource (a property of a resource)
delimiter & for more property

  • GET /cars?color=blue
  • GET /cars?color=blue&brand=ferrari

Naming

  • All lowercases
  • Hyphen separate words

Use correct HTTP status code

  • 200 for GET, PUT, POST, DELETE, ...
  • 201 specifically for POST, PUT
  • 204 for any methods, headers useful

Python naming

  • File: underscore
  • Method: underscore
  • Basic syntax
  • Backward compatibility
  • Response timeout
  • Auto JSON data transform
  • HTTP interceptor (change HTTP req from app to server, from server to app (e.g. logging, auth, retry failed HTTP req))
  • Download progress
  • Simultaneous reqs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment