curl -X PUT 'https://api.testingapis.com/api/Todos/31' \
-H 'Content-Type: application/json' \
-d '{"userId": 101, "title": "Review pull request #42", "completed": false, "priority": "high", "dueDate": "2025-07-20"}'
const res = await fetch("https://api.testingapis.com/api/Todos/31", {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: "{\"userId\": 101, \"title\": \"Review pull request #42\", \"completed\": false, \"priority\": \"high\", \"dueDate\": \"2025-07-20\"}",
});
console.log(res.status, await res.text());
// The shape of the example response in the docs.
type ApiResponse = {
message: string;
data: {
id: number;
userId: number;
title: string;
completed: boolean;
priority: string;
dueDate: string;
};
};
const res = await fetch("https://api.testingapis.com/api/Todos/31", {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: "{\"userId\": 101, \"title\": \"Review pull request #42\", \"completed\": false, \"priority\": \"high\", \"dueDate\": \"2025-07-20\"}",
});
const body = (await res.json()) as ApiResponse;
console.log(res.status, body);
import requests
res = requests.put(
"https://api.testingapis.com/api/Todos/31",
headers={
"Content-Type": "application/json",
},
data="{\"userId\": 101, \"title\": \"Review pull request #42\", \"completed\": false, \"priority\": \"high\", \"dueDate\": \"2025-07-20\"}",
)
print(res.status_code, res.text)
using System.Net.Http.Headers;
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Put, "https://api.testingapis.com/api/Todos/31");
request.Content = new StringContent("{\"userId\": 101, \"title\": \"Review pull request #42\", \"completed\": false, \"priority\": \"high\", \"dueDate\": \"2025-07-20\"}");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.testingapis.com/api/Todos/31"))
.header("Content-Type", "application/json")
.method("PUT", HttpRequest.BodyPublishers.ofString("{\"userId\": 101, \"title\": \"Review pull request #42\", \"completed\": false, \"priority\": \"high\", \"dueDate\": \"2025-07-20\"}"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
body := strings.NewReader("{\"userId\": 101, \"title\": \"Review pull request #42\", \"completed\": false, \"priority\": \"high\", \"dueDate\": \"2025-07-20\"}")
req, err := http.NewRequest("PUT", "https://api.testingapis.com/api/Todos/31", body)
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(res.StatusCode, string(data))
}