Get vs Post: When and why?

Hello,

I was just reading up about the difference between get and post and I don’t understand how something is sent through HTTP or saved in the URL. Does anyone have any examples?

Here’s an extract from W3’s page on the subject:

The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with method="post").

Thank you all for your non-stop help!

1 Like

you want to know about http “transfer protocol”? then you can look this up on some internet specially in text books otherwise describe your question further, thanks and happy learning :slight_smile:

If I were to use ‘get’, how does it show up in the URL? Are there any examples of what kind of information that would include? Would it be, say a forum title? What types of information would you use ‘get’ to receive?

Typically, using GET requests to retrieve data from API. There are many things you can be inclusive in the GET requests, params and queries are the most popular ones.

For example, getting a list of users. You can perform the request: GET /users
Or get a specific user using param: GET /users/1
Or get users within page 2 and limited by 10 using query: GET /users?page=1&limit=10

POST requests are usually used for creation, or transfer large data to the API by including the body to the request as a Stringify format.

For example, create a new user. You can perform the request like this: POST /users --data ‘{“name”: “Paul”,“age”:“30”}’

Readmore about the best practices here: Web API design best practices - Azure Architecture Center | Microsoft Learn

Hope it helps.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.