Requests
Query strings and request bodies
Decide whether request data belongs in the URL query string or in the message body, and understand how servers receive each form.
7 minute lesson
~~~
A query string is part of the URL:
/articles?tag=css&page=2
It works well for filters, searches, sorting, and pagination. Query parameters are visible in the address bar and easy to bookmark or share.
A request body carries data after the headers:
{
"title": "Learn HTTP",
"published": true
}
Bodies are common with POST, PUT, and PATCH. The Content-Type header tells the server how the body is encoded.
Do not put secrets in a query string. URLs often appear in browser history, logs, analytics, and referrer data. HTTPS encrypts a URL while it travels, but it does not stop these local and application-level records.
Lesson completed