Search the courses, subjects, tracks, games and features, or jump straight to a page.
5 cards from this section. Quick, good the night before a test.
When should you use a POST request instead of GET?
It usually modifies server state.
What status code indicates successful creation from a POST request?
Different from 200 OK.
Which status code usually means a POST request created a new resource?
It is one more than the plain OK code.
Which requests argument sends a dictionary as a JSON body and sets the Content-Type header automatically?
The argument has the same name as the format.
Write the server side of a create endpoint as a function handle_create(body_text) that returns a status code and a reply. It must answer 400 with an error message when the body is not valid JSON or has no title, and 201 with the created object otherwise. Then write client code that prints a suitable message for each case.
`json.loads` raises `ValueError` (its `JSONDecodeError` is a subclass) for text that is not JSON.
Using only urllib.request, write make_post(url, payload, as_json) that builds (but does not send) a POST request carrying the payload either as JSON or as form data, with the matching Content-Type. Print the method, the Content-Type and the body for both forms.
`urllib` stores header names with only the first letter capitalized, so read it back with `get_header("Content-type")`.
6 more questions in this section. Enroll free to practise them all.
Enroll free