Bitzu

CPSA ยท Web servers, architecture and protocols

HTTP methods and response codes

GET, POST, PUT, DELETE, OPTIONS, TRACE and the meaning of status code classes.

Key points

  • Methods: GET retrieves, POST submits data, PUT replaces, DELETE removes, HEAD returns headers only, OPTIONS asks what is supported, TRACE echoes the request.
  • Safe: GET, HEAD, OPTIONS, TRACE. Idempotent: PUT, DELETE.
  • Status classes: 1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error.
  • Finding: unneeded PUT/DELETE or TRACE enabled.
  • Access mapping: 401 not authenticated, 403 refused, 404 not found.

Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods

Practice questions

Single choice

Which status code class means the server failed to fulfil a valid request?

  1. 2xx
  2. 3xx
  3. 4xx
  4. 5xx
Show answer

Answer: D. 5xx

5xx means a server error. 4xx means the client request is at fault, 3xx is redirection and 2xx is success.

Select all that apply

Which HTTP methods are idempotent according to the standard semantics?

  1. PUT
  2. DELETE
  3. POST
  4. PATCH
  5. CONNECT
Show answer

Answer: A. PUT, B. DELETE

PUT and DELETE are idempotent: repeating them gives the same end state. POST and PATCH are not idempotent, and CONNECT sets up a tunnel.

True or false

True or false: a 404 response always proves the resource does not exist.

Show answer

Answer: False

False. Servers may return 404 instead of 403 to hide a resource from unauthorised clients, so 404 does not always prove absence.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More CPSA topics in this module