Day 2 of 5
⏱ ~60 minutes
Networking for Developers — Day 2

HTTP Deep Dive

Methods, status codes, headers, CORS, cookies, and caching — everything in the browser's Network tab explained.

HTTP Methods

HTTP Methods
GET     → retrieve a resource (no body)
POST    → create a resource (has a body)
PUT     → replace a resource entirely
PATCH   → partial update
DELETE  → delete a resource
HEAD    → like GET but returns only headers
OPTIONS → preflight for CORS, returns allowed methods
Status Codes
# 2xx Success
200 OK
201 Created
204 No Content

# 3xx Redirect
301 Moved Permanently
302 Found (temporary redirect)
304 Not Modified (use cache)

# 4xx Client Error
400 Bad Request
401 Unauthorized (not authenticated)
403 Forbidden (authenticated but not allowed)
404 Not Found
422 Unprocessable Entity (validation failed)
429 Too Many Requests

# 5xx Server Error
500 Internal Server Error
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
Important Headers
# Request headers
Authorization: Bearer 
Content-Type: application/json
Accept: application/json
Cookie: session=abc123
Origin: https://myfrontend.com

# Response headers
Content-Type: application/json; charset=utf-8
Set-Cookie: session=abc123; HttpOnly; Secure; SameSite=Lax
Access-Control-Allow-Origin: https://myfrontend.com
Cache-Control: max-age=3600
X-RateLimit-Remaining: 47
CORS in a nutshell
# Browser blocks cross-origin requests by default
# Server opts in by sending:
Access-Control-Allow-Origin: https://myfrontend.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Content-Type, Authorization

# Preflight (OPTIONS) happens first for non-simple requests
# curl shows what the browser hides:
curl -v -X OPTIONS https://api.example.com/users \
  -H 'Origin: https://myfrontend.com'
📝 Day 2 Exercise
Read HTTP Headers
  1. O
  2. p
  3. e
  4. n
  5. b
  6. r
  7. o
  8. w
  9. s
  10. e
  11. r
  12. D
  13. e
  14. v
  15. T
  16. o
  17. o
  18. l
  19. s
  20. N
  21. e
  22. t
  23. w
  24. o
  25. r
  26. k
  27. t
  28. a
  29. b
  30. .
  31. L
  32. o
  33. a
  34. d
  35. a
  36. s
  37. i
  38. t
  39. e
  40. a
  41. n
  42. d
  43. f
  44. i
  45. n
  46. d
  47. :
  48. t
  49. h
  50. e
  51. C
  52. o
  53. n
  54. t
  55. e
  56. n
  57. t
  58. -
  59. T
  60. y
  61. p
  62. e
  63. o
  64. f
  65. t
  66. h
  67. e
  68. H
  69. T
  70. M
  71. L
  72. r
  73. e
  74. s
  75. p
  76. o
  77. n
  78. s
  79. e
  80. ,
  81. t
  82. h
  83. e
  84. S
  85. e
  86. t
  87. -
  88. C
  89. o
  90. o
  91. k
  92. i
  93. e
  94. h
  95. e
  96. a
  97. d
  98. e
  99. r
  100. ,
  101. a
  102. n
  103. y
  104. C
  105. O
  106. R
  107. S
  108. h
  109. e
  110. a
  111. d
  112. e
  113. r
  114. s
  115. ,
  116. a
  117. n
  118. d
  119. a
  120. 3
  121. 0
  122. 4
  123. N
  124. o
  125. t
  126. M
  127. o
  128. d
  129. i
  130. f
  131. i
  132. e
  133. d
  134. r
  135. e
  136. s
  137. p
  138. o
  139. n
  140. s
  141. e
  142. (
  143. r
  144. e
  145. l
  146. o
  147. a
  148. d
  149. t
  150. h
  151. e
  152. p
  153. a
  154. g
  155. e
  156. )
  157. .

Day 2 Summary

  • GET = read. POST = create. PUT = replace. PATCH = update. DELETE = remove. Use them correctly.
  • 401 = not logged in. 403 = logged in but not allowed. 404 = not found. 500 = server broke.
  • CORS: browsers block cross-origin requests unless the server explicitly allows them.
  • Cache-Control: max-age=3600 tells the browser to cache for 1 hour. 304 = use the cached version.
Finished this lesson?