Sobes.tech
Junior — Middle

Can you list the main types of HTTP requests and their purpose?

sobes.tech AI

Answer from AI

Main types of HTTP requests and their purpose:

  • GET — requests data from the server. Used to retrieve information without changing the state.
  • POST — sends data to the server, usually to create new resources.
  • PUT — updates an existing resource or creates it if it does not exist.
  • DELETE — deletes the specified resource on the server.
  • PATCH — partially updates a resource, changing only specified fields.
  • HEAD — requests only response headers, without the body, to check metadata.

Example of using a GET request in Flutter with the http package:

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

void fetchData() async {
  final response = await http.get(Uri.parse('https://example.com/data'));
  if (response.statusCode == 200) {
    print('Data received: ${response.body}');
  } else {
    print('Error: ${response.statusCode}');
  }
}
Can you list the main types of HTTP requests and… - sobes.tech