Sobes.tech
Junior — Middle

Can you explain what is meant by an HTTP PUT request?

sobes.tech AI

Answer from AI

The HTTP PUT request is used to send data to a server to create or replace a resource at the specified URL. Unlike POST, which typically adds a new resource, PUT usually updates an existing one or creates a new one if it does not exist. The PUT request is considered idempotent, meaning that repeated requests with the same data will not change the result.

Example of usage in Flutter with the http package:

import 'package:http/http.dart' as http;

void updateResource() async {
  final url = Uri.parse('https://example.com/api/resource/1');
  final response = await http.put(
    url,
    headers: {'Content-Type': 'application/json'},
    body: '{"name": "New Name"}',
  );
  if (response.statusCode == 200) {
    print('Resource updated');
  } else {
    print('Update error: ${response.statusCode}');
  }
}
Can you explain what is meant by an HTTP PUT request… - sobes.tech