HTML HTTP मेथड्स
In this page:
GET मेथड
GET method किसी server से data प्राप्त करने के लिए इस्तेमाल होता है। यह read-only और idempotent है, यानी एक जैसी request कई बार भेजने पर भी server पर कुछ भी बदले बिना वही result मिलता है।
उदाहरण: The GET Method
<form action="/search" method="get">
<input type="text" name="q">
</form>
POST मेथड
POST method किसी resource को create या update करने के लिए server को data भेजने के लिए इस्तेमाल होता है। data URL में जोड़े जाने की बजाय HTTP request body के अंदर सुरक्षित तरीके से पैक किया जाता है।
उदाहरण: The POST Method
<form action="/upload" method="post">
<input type="file" name="file">
</form>
PUT मेथड
PUT method किसी मौजूदा resource को update करने या न होने पर नया बनाने के लिए इस्तेमाल होता है। यह idempotent है, यानी एक ही update को कई बार भेजने पर भी वही final server state मिलता है।
उदाहरण: The PUT Method
<script>
fetch('/api/profile/1', { method: 'PUT', body: JSON.stringify({ name: 'Alex' }) });
</script>
DELETE मेथड
DELETE method server से किसी specified resource को स्थायी रूप से हटाने के लिए इस्तेमाल होता है। PUT की तरह, इसे भी JavaScript fetch requests से ही trigger करना होता है क्योंकि यह HTML forms में natively supported नहीं है।
उदाहरण: The DELETE Method
<script>
fetch('/api/records/5', { method: 'DELETE' });
</script>
फॉर्म्स के लिए GET बनाम POST चुनना
GET और POST में चुनाव आपके form की प्रकृति पर निर्भर करता है। get non-sensitive search queries के लिए बेहतरीन है क्योंकि यह users को results bookmark और share करने देता है।
logins, registration, और file uploads के लिए POST ज़रूरी है, क्योंकि यह data को सुरक्षित और छिपा हुआ रखता है।
उदाहरण: Choosing GET vs. POST for Forms
<form action="/search" method="get">
<input type="text" name="q">
</form>
<form action="/register" method="post">
<input type="password" name="password">
</form>
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: