Member-only story
Common HTTP Request Method
HTTP methods that developers should know
If you’re working on anything online, you’ll definitely come across HTTP request methods, whether you realize it or not. These methods are fundamental to web development, making the essential connections between the client and server possible. Let’s take a closer look at these methods, discuss possible weaknesses and talk about the best ways to handle them.
HTTP GET
The GET method is used to obtain a resource from the server. It’s similar to requesting, “Hey, can you please provide me with this information?” Whenever you click on a link or enter a URL in your browser, you are using the GET method.
For instance, consider an API with a /customers
endpoint. A GET request to this endpoint would typically retrieve a list of all the customers. Because of a GET request only shows data without altering any resources, it is regarded as both safe and idempotent in resource representation context.
Example Usage:
fetch('https://api.example.com/customers')
.then(response => response.json())
.then(data => console.log(data));
This is how the values handled by the target server:
GET /api/customers HTTP/1.1
Host: api.example.com
Best Practices
Since GET requests are meant to retrieve data without affecting server data, use them when you need to pull information. And yes, the backend are the one who control the request and what should do, so, making sure the backend are using the appropriate method validation for this practices. Also, because they’re cached by browsers, they’re great for improving loading speeds for unchanged resources.
Security Tips:
However, this is where most of the developers making a mistake where they are exposing sensitive information which falls under OWASP Top 10: Sensitive Data Exposure. Be cautious not to include sensitive data while retrieving data which leads to data breach, system information mass assignment and business disruption.
HTTP POST
POST method is commonly used (should be used) to create new or update resources. The HTTP POST…