How REST APIs Work: Build One with the Standard Library
9 calls to a tiny notes API gave 6 status codes, from 200 to 405.
Video #277 ยท How it works, by example
Steps in the video
Files
- api.py (83 lines)
- client.py (17 lines)
- run.py (29 lines)
Tested with
Python 3.12.15
What this does not show
The notes and the server are a made-up toy for teaching. HEAD and OPTIONS get 501, and there is no authentication.
Sources
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
- https://docs.python.org/3.12/library/http.server.html
- https://docs.python.org/3.12/library/urllib.error.html
- https://ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
- https://www.rfc-editor.org/rfc/rfc5789.html
- https://www.rfc-editor.org/rfc/rfc9110.html
Learning IT by Example.