Junior — Middle
Can you list the main types of network requests used in communication between a client and a server?
sobes.tech AI
Answer from AI
The main types of network requests used in client-server communications typically correspond to HTTP methods:
- GET — request to retrieve data from the server.
- POST — send data to the server to create a resource.
- PUT — update an existing resource on the server.
- DELETE — delete a resource.
- PATCH — partially update a resource.
- HEAD — retrieve only response headers without the body.
In iOS, these requests are usually performed using URLSession, for example:
let url = URL(string: "https://api.example.com/items")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
// handle response
}
task.resume()
These methods facilitate client-server interaction via REST or other protocols.