Skip to main content

URLs, Hosts and Ports

What this concept is​

A URL identifies a resource and how to address it. In http://127.0.0.1:8765/sessions, http is the scheme, 127.0.0.1 the host address, 8765 the port and /sessions the path. A domain name normally requires name resolution; an explicit IP address does not exercise that step.

Why it matters here​

A browser and your Python client can contact the same service. Knowing each part of the address helps separate “wrong resource” from “no server listening.”

Concrete example​

The lab server binds only to 127.0.0.1, the local machine's loopback address, and can request an available port from the operating system. It prints the chosen URL. If you substitute a different port, you may contact another service or find none at all. Changing /sessions to /missing keeps the same host and port but requests a different resource.

A fragment such as #section is normally interpreted by a browser and is not part of the HTTP request target. Query parameters can affect server behavior. This simple fixture uses exact paths and deliberately does not implement query filtering.

Common confusion / misconception​

Localhost on another person's laptop refers to that laptop, not yours. A URL is not proof a server exists. HTTP and HTTPS are different schemes; our loopback exercise does not teach or verify a real TLS connection.

How to use it​

Parse an address into parts before making a request. Start the fixture, copy its printed port and try the documented path. When investigating a failure, check scheme, host, port and path in that order. Do not expose the teaching server on a public network or add credentials for this exercise.

Check yourself​

If the server returns 404, did the request necessarily fail to reach any server? No. An HTTP server responded but did not provide that resource. Connection refusal happens earlier.

Mini drill or application​

Annotate the fixture URL on paper. Predict the effect of changing only its path, then only its port. Perform the path experiment locally; explain what evidence would distinguish the failures.

Read this only if stuck​

MDN: how the Internet works supplies the broader picture. HTTP overview connects it to messages.