How do I send an HTTP GET request? [Curl/Bash Code]
The GET request method is used to fetch data from the server. In this HTTP GET request example, we are downloading the content of the ReqBin echo URL. The Accept: */* request header tells the server that the client accepts all media types. The Content-Type: text/html response header informs the client that the server returned HTML for this HTTP GET request. The Curl/Bash code was automatically generated for the GET Request example.
The Hypertext Transfer Protocol (HTTP) is the core of the World Wide Web and powers websites and mobile applications. The HTTP is designed to transfer information between networked devices and provides a framework for client/server communication. HTTP works as a request/response protocol between client and server. For example, a browser (client) sends an HTTP GET request to a web server (server); the server then returns the response to the browser. The HTTP request contains the HTTP method (mostly GET), target URL, HTTP request headers, and additional URL parameters. The HTTP response contains information about the status of the request (mostly 200), and the requested content (HTML, JSON, image, etc.) and optional HTTP headers on how to interpret this content.
HTTP GET Request Format
The GET request consists or request-line and HTTP headers section. The GET request-line begins with an HTTP method token, followed by the request URI and the protocol version, and ending with CRLF. The elements are separated by space characters. Below is an example of a GET request to the ReqBin echo server.
HTTP GET Request Example
GET /echo HTTP/1.1
Some notes on HTTP GET Requests
- GET request method is used to get a resource from the server. - GET requests cannot have a message body but you still can send data to the server using the URL parameters. - GET requests should only receive data. If you want to change data on the server, use POST, PUT, PATCH or DELETE methods. - GET method is defined as idempotent, which means that multiple identical GET requests should have the same effect as a single request.
HTTP GET Request Examples
Example of getting HTML page from ReqBin echo URL.
GET HTML Request Example
GET /echo HTTP/1.1
Example of getting JSON data from ReqBin echo URL.
GET JSON Request Example
GET /echo/get/json HTTP/1.1
Example of getting XML data from ReqBin echo URL.
GET XML Request Example
GET /echo/get/xml HTTP/1.1