0

I am currently learning about how to transfer messages via URL to a host server. What I have learned so far is how a URL is composed: http://example.com:80/latest/example.jpg?d=400x400 gives me the image example.jpg in the dimension requested from the host via port 80 (which can be left out as HTTP always uses port 80). The request message for this would look like this: GET latest/example.jpg?d=400x400 HTTP/1.1. The response message would look like this: HTTP/1.1 200 OK.

So it is clear to me how to GET some resource from a Host. But what's with the other HTTP methods like PUT, POST or DELETE? I don't understand where in the URL the HTTP method is carried for the host to read. How do I tell the host to PUT instead of GET?

1
  • The URL didn't contain the GET, and it doesn't contain the POST or PUT either. This is in the request header. Commented Jul 1, 2022 at 9:30

1 Answer 1

2

There seems to be a small misconception about urls and the corresponding requests.

The url http://example.com:80/latest/example.jpg?d=400x400 is composed of 5 pieces:

  • The used protocol (in your case http)
  • The use fqdn - fully qualified domain name - (in your case example.com)
  • The port on the fqdn - in your case 80 - which is in your case unnecessary because your browser will default to 80 for http
  • your requested resource, in your case /latest/example.jpg
  • your requested query string parameters, indicated by ?, in your case the parameter d with the value 400x400

Note that the request message only looks like you outlined, because your browser defaults to the GET method of HTTP. As you correctly stated, there are various HTTP methods, such as PUT, POST, PATCH, DELETE, etc.

The HTTP-Method is stated in the HTTP Header, so it's up to the request which HTTP-Method is invoked.

For the "well-known" internet surfing, your typed url will always result in a GET request. For the other HTTP methods, it's up to the application (e.g. your Website or your normal software that uses HTTP requests) to enable the use. As an example, html enables the use of <form> tags where you can specify the http method, e.g. you can say to use POST.

To sum it up: Your url does not specify the HTTP-Methods.

Browsers default to GET, but in the end it's up to your application (and thus the logic behind it) which HTTP-method is used.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.