Choose HTTP methods that align with the actual operation being performed. Use GET for retrieving data with query parameters, and POST for operations that modify state or require complex request bodies.
Choose HTTP methods that align with the actual operation being performed. Use GET for retrieving data with query parameters, and POST for operations that modify state or require complex request bodies.
When designing API endpoints:
// Better approach for data retrieval
const res = await fetchHandler(`${BASE_PATH}/api/check-cname?domain=${domain}`, {
headers,
method: 'GET'
});
const res = await fetchHandler(`${BASE_PATH}/api/resource`, {
headers,
method: 'POST',
body: JSON.stringify(payload)
});
if (req.method === 'GET') {
const payload = { ...toForward, project_tier }
return retrieveData(name as string, payload)
} else if (req.method === 'POST') {
const payload = { ...req.body, project_tier }
return retrieveData(name as string, payload)
}
This practice ensures API endpoints follow RESTful conventions, improves API discoverability, and allows for proper caching mechanisms.
Enter the URL of a public GitHub repository