Difference between GET and POST Method
GET and POST are HTTP verbs used to query the server for some information.Both can be used to achieve same goal but incorrect choice of HTTP verbs may lead to unexpected outcomes.
GET is a read-only operation which can be used for safe actions. It can be repeated without affecting the state of the resource.It is used to retrieve current state of the resource from the server.
POST is a read-write operation and may change the state of the resource and provoke side effects on the server.It is used to initialize the state of a new resource using given URL. We can use POST when we are dealing with sensitive data and when we have long requests.
Difference between GET and POST Method
GET | POST |
GET request is sent via URL | POST requests are encapsulated in form of HTTP request |
Data is appended to the URL | Data can either appended to the URL or in the body of request. |
Data is publicly available | Data is private for “HTTPS” sessions otherwise it is public |
It is used to both send and receive data | It is used to both send and receive data |
GET is only used to retrieve data from the information server | POST can also be used to add or update new data to the information server |
GET appends all the data to URL and shows in the URL bar of the browser | POST wont show up the request in URL bar |
The amount of data using GET method is restricted to 1024 character as URLs can only be of 1024 characters. It can’t be more than 255 character long | POST is not restricted to any textual data. |
GET is not possible to send any files or binary data | POST is possible to send files and binary data |
GET request is faster. | POST requests are slower in comparison to GET requests |
GET is used for safe action | POST is used for unsafe option |
GET request can be Bookmarked | POST request can’t be Bookmarked |
GET request can be cached | POST request can’t be cached |
Sample GET request:
https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4
Sample POST request:
POST https://www.googleapis.com/doubleclicksearch/v2/reports
Authorization: Bearer your OAuth 2.0 access token
Content–type: application/json
{
“reportScope”: {
“agencyId”: “your agency ID“,
“advertiserId”: “your advertiser ID“
},
“reportType”: “campaign”,
“columns”: [
{ “columnName”: “campaignId” },
{ “columnName”: “campaign” }
],
“downloadFormat”: “csv”,
“maxRowsPerFile”: 6000000,
“statisticsCurrency”: “agency”
}