{"schemaVersion":1,"title":"Posts · OpenAPI sample","url":"https://appgram.github.io/docsy/versions/current/fr/api/posts","markdownUrl":"https://appgram.github.io/docsy/format-md/versions/current/fr/api/posts","jsonUrl":"https://appgram.github.io/docsy/agent/pages/versions/current/fr/api/posts.json","version":"current","locale":"fr","markdown":"# Posts · OpenAPI sample\n\nPublic JSONPlaceholder requests, generated from a local OpenAPI file. Copy GET, POST, PUT, PATCH, and DELETE examples. Writes are simulated and are not persisted.\n\n> Source: https://appgram.github.io/docsy/versions/current/fr/api/posts  \n> Endpoints: 6  \n> API version: v1.0.0\n\nSee [How this OpenAPI sample works](/docsy/versions/current/fr/guides/tutorials/openapi-ingestion) for the base setup.\n\n### List posts\n\nRead posts, optionally filtering by user. The sample query uses `userId=1`; no authentication is required.\n\n**`GET`** `/posts`\n\n**Query parameters**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `userId` | `integer` |  | Return posts belonging to this user. Omit the parameter to list all posts. |\n\n**Request**\n\n**cURL**\n\n```bash\ncurl --request GET \\\n  --url 'https://jsonplaceholder.typicode.com/posts?userId=1'\n```\n\n**JavaScript · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts?userId=1\", {\n  method: \"GET\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**TypeScript · fetch**\n\n```typescript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts?userId=1\", {\n  method: \"GET\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Node.js · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts?userId=1\", {\n  method: \"GET\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Python · requests**\n\n```python\nimport requests\n\nresponse = requests.request(\n    \"GET\",\n    \"https://jsonplaceholder.typicode.com/posts?userId=1\",\n    headers={},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.text)\n\n```\n\n**Go · net/http**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://jsonplaceholder.typicode.com/posts?userId=1\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n\n}\n```\n\n**Java · HttpClient**\n\n```java\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://jsonplaceholder.typicode.com/posts?userId=1\"))\n    .method(\"GET\", HttpRequest.BodyPublishers.noBody())\n    .build();\nHttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());\nSystem.out.println(response.body());\n```\n\n**Kotlin · OkHttp**\n\n```kotlin\n// Requires OkHttp 4.x.\nimport okhttp3.OkHttpClient\nimport okhttp3.Request\nimport okhttp3.MediaType.Companion.toMediaType\nimport okhttp3.RequestBody.Companion.toRequestBody\n\nfun main() {\n  val request = Request.Builder()\n    .url(\"https://jsonplaceholder.typicode.com/posts?userId=1\")\n    .method(\"GET\", null)\n    .build()\n  OkHttpClient().newCall(request).execute().use { response ->\n    println(response.body?.string())\n  }\n}\n\n```\n\n**C# · HttpClient**\n\n```csharp\nusing System.Net.Http.Headers;\nvar client = new HttpClient();\nvar request = new HttpRequestMessage\n{\n    Method = HttpMethod.Get,\n    RequestUri = new Uri(\"https://jsonplaceholder.typicode.com/posts?userId=1\"),\n};\nusing (var response = await client.SendAsync(request))\n{\n    response.EnsureSuccessStatusCode();\n    var body = await response.Content.ReadAsStringAsync();\n    Console.WriteLine(body);\n}\n```\n\n**C · libcurl**\n\n```c\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"GET\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts?userId=1\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**C++ · libcurl**\n\n```cpp\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"GET\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts?userId=1\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**Rust · reqwest**\n\n```rust\n// Cargo: reqwest = \"0.12\", tokio = { version = \"1\", features = [\"full\"] }\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n    let response = reqwest::Client::new()\n        .request(reqwest::Method::from_bytes(\"GET\".as_bytes())?, \"https://jsonplaceholder.typicode.com/posts?userId=1\")\n        .send().await?\n        .error_for_status()?;\n    println!(\"{}\", response.text().await?);\n    Ok(())\n}\n\n```\n\n**Swift · URLSession**\n\n```swift\nimport Foundation\n\nvar request = URLRequest(url: URL(string: \"https://jsonplaceholder.typicode.com/posts?userId=1\")!)\nrequest.httpMethod = \"GET\"\nlet (data, _) = try await URLSession.shared.data(for: request)\nprint(String(decoding: data, as: UTF8.self))\n\n```\n\n**Objective-C · NSURLSession**\n\n```objectivec\n#import <Foundation/Foundation.h>\n\nint main(void) {\n  @autoreleasepool {\n    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@\"https://jsonplaceholder.typicode.com/posts?userId=1\"]];\n    request.HTTPMethod = @\"GET\";\n    dispatch_semaphore_t done = dispatch_semaphore_create(0);\n    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {\n      if (error) NSLog(@\"%@\", error);\n      else NSLog(@\"%@\", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);\n      dispatch_semaphore_signal(done);\n    }] resume];\n    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);\n  }\n  return 0;\n}\n\n```\n\n**Dart · http**\n\n```dart\n// Requires package:http in pubspec.yaml.\nimport 'package:http/http.dart' as http;\n\nFuture<void> main() async {\n  final request = http.Request(\"GET\", Uri.parse(\"https://jsonplaceholder.typicode.com/posts?userId=1\"));\n  request.headers.addAll({\n  });\n  final response = await request.send();\n  print(await response.stream.bytesToString());\n}\n\n```\n\n**PHP · cURL**\n\n```php\n<?php\n$curl = curl_init('https://jsonplaceholder.typicode.com/posts?userId=1');\ncurl_setopt_array($curl, [\n    CURLOPT_CUSTOMREQUEST => 'GET',\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_TIMEOUT => 30,\n    CURLOPT_HTTPHEADER => [],\n]);\n$response = curl_exec($curl);\nif ($response === false) { throw new RuntimeException(curl_error($curl)); }\ncurl_close($curl);\necho $response;\n\n```\n\n**Ruby · Net::HTTP**\n\n```ruby\nrequire 'uri'\nrequire 'net/http'\n\nurl = URI(\"https://jsonplaceholder.typicode.com/posts?userId=1\")\nhttp = Net::HTTP.new(url.host, url.port)\nhttp.use_ssl = url.scheme == 'https'\nrequest = Net::HTTPGenericRequest.new(\"GET\", false, true, url.request_uri, {})\nresponse = http.request(request)\nputs response.body\n\n```\n\n**Scala · Java HttpClient**\n\n```scala\nimport java.net.URI\nimport java.net.http.{HttpClient, HttpRequest, HttpResponse}\n\nobject Example extends App {\n  val request = HttpRequest.newBuilder(URI.create(\"https://jsonplaceholder.typicode.com/posts?userId=1\"))\n    .method(\"GET\", HttpRequest.BodyPublishers.noBody())\n    .build()\n  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())\n  println(response.body())\n}\n\n```\n\n**Elixir · :httpc**\n\n```elixir\n:inets.start()\n:ssl.start()\nurl = String.to_charlist(\"https://jsonplaceholder.typicode.com/posts?userId=1\")\nheaders = []\nhttp_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]\n{:ok, {{_, status, _}, _, body}} = :httpc.request(:get, {url, headers}, http_options, [body_format: :binary])\nIO.inspect(status)\nIO.puts(body)\n\n```\n\n**Lua · Lua-cURL**\n\n```lua\n-- Requires Lua-cURL; libcurl retains its default TLS verification.\nlocal curl = require('cURL')\nlocal response = {}\nlocal request = curl.easy {\n  url = \"https://jsonplaceholder.typicode.com/posts?userId=1\",\n  customrequest = \"GET\",\n  httpheader = {\n  },\n  writefunction = function(chunk)\n    response[#response + 1] = chunk\n    return #chunk\n  end\n}\nrequest:perform()\nrequest:close()\nprint(table.concat(response))\n\n```\n\n**F# · HttpClient**\n\n```fsharp\nopen System.Net.Http\nopen System.Text\n\nuse client = new HttpClient()\nuse request = new HttpRequestMessage(HttpMethod(\"GET\"), \"https://jsonplaceholder.typicode.com/posts?userId=1\")\nuse response = client.SendAsync(request).GetAwaiter().GetResult()\nprintfn \"%s\" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n\n```\n\n**Visual Basic · HttpClient**\n\n```visualbasic\nImports System.Net.Http\nImports System.Text\n\nModule Example\n  Sub Main()\n    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod(\"GET\"), \"https://jsonplaceholder.typicode.com/posts?userId=1\")\n      Using response = client.SendAsync(request).GetAwaiter().GetResult()\n        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n      End Using\n    End Using\n  End Sub\nEnd Module\n\n```\n\n**PowerShell · Invoke-RestMethod**\n\n```powershell\n$headers = @{\n}\n$response = Invoke-RestMethod -Method 'GET' -Uri 'https://jsonplaceholder.typicode.com/posts?userId=1' -Headers $headers\n$response | ConvertTo-Json -Depth 20\n\n```\n\n**R · httr**\n\n```r\nlibrary(httr)\n\nheaders <- setNames(c(), c())\nresponse <- VERB(\"GET\", \"https://jsonplaceholder.typicode.com/posts?userId=1\", add_headers(.headers = headers))\nstop_for_status(response)\ncat(content(response, as = \"text\", encoding = \"UTF-8\"))\n\n```\n\n**Response** — `200`\n\n```json\n[\n  {\n    \"id\": 1,\n    \"userId\": 1,\n    \"title\": \"An example post\",\n    \"body\": \"Example response content. Live post text can differ.\"\n  }\n]\n```\n\n---\n\n### Create a post\n\nSend a JSON request body. JSONPlaceholder returns a simulated creation response; a later GET will not retrieve this new post.\n\n**`POST`** `/posts`\n\n**Body**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `title` | `string` | ✓ | The post title. |\n\n| `body` | `string` | ✓ | Plain-text content of the post. |\n\n| `userId` | `integer` | ✓ | User associated with the post. |\n\n**Request**\n\n**cURL**\n\n```bash\ncurl --request POST \\\n  --url 'https://jsonplaceholder.typicode.com/posts' \\\n  --header 'Content-Type: application/json' \\\n  --data '{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}'\n```\n\n**JavaScript · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts\", {\n  method: \"POST\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**TypeScript · fetch**\n\n```typescript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts\", {\n  method: \"POST\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Node.js · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts\", {\n  method: \"POST\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Python · requests**\n\n```python\nimport requests\n\nresponse = requests.request(\n    \"POST\",\n    \"https://jsonplaceholder.typicode.com/posts\",\n    headers={\"Content-Type\": \"application/json\"},\n    data=\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\".encode(\"utf-8\"),\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.text)\n\n```\n\n**Go · net/http**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://jsonplaceholder.typicode.com/posts\"\n\n\tpayload := strings.NewReader(\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\")\n\n\treq, _ := http.NewRequest(\"POST\", url, payload)\n\n\treq.Header.Add(\"Content-Type\", \"application/json\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n\n}\n```\n\n**Java · HttpClient**\n\n```java\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://jsonplaceholder.typicode.com/posts\"))\n    .header(\"Content-Type\", \"application/json\")\n    .method(\"POST\", HttpRequest.BodyPublishers.ofString(\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\"))\n    .build();\nHttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());\nSystem.out.println(response.body());\n```\n\n**Kotlin · OkHttp**\n\n```kotlin\n// Requires OkHttp 4.x.\nimport okhttp3.OkHttpClient\nimport okhttp3.Request\nimport okhttp3.MediaType.Companion.toMediaType\nimport okhttp3.RequestBody.Companion.toRequestBody\n\nfun main() {\n  val request = Request.Builder()\n    .url(\"https://jsonplaceholder.typicode.com/posts\")\n    .method(\"POST\", \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\".toRequestBody(\"application/json\".toMediaType()))\n    .addHeader(\"Content-Type\", \"application/json\")\n    .build()\n  OkHttpClient().newCall(request).execute().use { response ->\n    println(response.body?.string())\n  }\n}\n\n```\n\n**C# · HttpClient**\n\n```csharp\nusing System.Net.Http.Headers;\nvar client = new HttpClient();\nvar request = new HttpRequestMessage\n{\n    Method = HttpMethod.Post,\n    RequestUri = new Uri(\"https://jsonplaceholder.typicode.com/posts\"),\n    Content = new StringContent(\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\")\n    {\n        Headers =\n        {\n            ContentType = new MediaTypeHeaderValue(\"application/json\")\n        }\n    }\n};\nusing (var response = await client.SendAsync(request))\n{\n    response.EnsureSuccessStatusCode();\n    var body = await response.Content.ReadAsStringAsync();\n    Console.WriteLine(body);\n}\n```\n\n**C · libcurl**\n\n```c\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"POST\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts\");\n\nstruct curl_slist *headers = NULL;\nheaders = curl_slist_append(headers, \"Content-Type: application/json\");\ncurl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);\n\ncurl_easy_setopt(hnd, CURLOPT_POSTFIELDS, \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**C++ · libcurl**\n\n```cpp\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"POST\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts\");\n\nstruct curl_slist *headers = NULL;\nheaders = curl_slist_append(headers, \"Content-Type: application/json\");\ncurl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);\n\ncurl_easy_setopt(hnd, CURLOPT_POSTFIELDS, \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**Rust · reqwest**\n\n```rust\n// Cargo: reqwest = \"0.12\", tokio = { version = \"1\", features = [\"full\"] }\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n    let response = reqwest::Client::new()\n        .request(reqwest::Method::from_bytes(\"POST\".as_bytes())?, \"https://jsonplaceholder.typicode.com/posts\")\n        .header(\"Content-Type\", \"application/json\")\n        .body(\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\")\n        .send().await?\n        .error_for_status()?;\n    println!(\"{}\", response.text().await?);\n    Ok(())\n}\n\n```\n\n**Swift · URLSession**\n\n```swift\nimport Foundation\n\nvar request = URLRequest(url: URL(string: \"https://jsonplaceholder.typicode.com/posts\")!)\nrequest.httpMethod = \"POST\"\nrequest.setValue(\"application/json\", forHTTPHeaderField: \"Content-Type\")\nrequest.httpBody = Data(\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\".utf8)\nlet (data, _) = try await URLSession.shared.data(for: request)\nprint(String(decoding: data, as: UTF8.self))\n\n```\n\n**Objective-C · NSURLSession**\n\n```objectivec\n#import <Foundation/Foundation.h>\n\nint main(void) {\n  @autoreleasepool {\n    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@\"https://jsonplaceholder.typicode.com/posts\"]];\n    request.HTTPMethod = @\"POST\";\n    [request setValue:@\"application/json\" forHTTPHeaderField:@\"Content-Type\"];\n    request.HTTPBody = [@\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\" dataUsingEncoding:NSUTF8StringEncoding];\n    dispatch_semaphore_t done = dispatch_semaphore_create(0);\n    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {\n      if (error) NSLog(@\"%@\", error);\n      else NSLog(@\"%@\", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);\n      dispatch_semaphore_signal(done);\n    }] resume];\n    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);\n  }\n  return 0;\n}\n\n```\n\n**Dart · http**\n\n```dart\n// Requires package:http in pubspec.yaml.\nimport 'package:http/http.dart' as http;\n\nFuture<void> main() async {\n  final request = http.Request(\"POST\", Uri.parse(\"https://jsonplaceholder.typicode.com/posts\"));\n  request.headers.addAll({\n    \"Content-Type\": \"application/json\",\n  });\n  request.body = \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\";\n  final response = await request.send();\n  print(await response.stream.bytesToString());\n}\n\n```\n\n**PHP · cURL**\n\n```php\n<?php\n$curl = curl_init('https://jsonplaceholder.typicode.com/posts');\ncurl_setopt_array($curl, [\n    CURLOPT_CUSTOMREQUEST => 'POST',\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_TIMEOUT => 30,\n    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],\n    CURLOPT_POSTFIELDS => '{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}',\n]);\n$response = curl_exec($curl);\nif ($response === false) { throw new RuntimeException(curl_error($curl)); }\ncurl_close($curl);\necho $response;\n\n```\n\n**Ruby · Net::HTTP**\n\n```ruby\nrequire 'uri'\nrequire 'net/http'\n\nurl = URI(\"https://jsonplaceholder.typicode.com/posts\")\nhttp = Net::HTTP.new(url.host, url.port)\nhttp.use_ssl = url.scheme == 'https'\nrequest = Net::HTTPGenericRequest.new(\"POST\", true, true, url.request_uri, {\"Content-Type\" => \"application/json\"})\nrequest.body = \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\"\nresponse = http.request(request)\nputs response.body\n\n```\n\n**Scala · Java HttpClient**\n\n```scala\nimport java.net.URI\nimport java.net.http.{HttpClient, HttpRequest, HttpResponse}\n\nobject Example extends App {\n  val request = HttpRequest.newBuilder(URI.create(\"https://jsonplaceholder.typicode.com/posts\"))\n    .header(\"Content-Type\", \"application/json\")\n    .method(\"POST\", HttpRequest.BodyPublishers.ofString(\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\"))\n    .build()\n  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())\n  println(response.body())\n}\n\n```\n\n**Elixir · :httpc**\n\n```elixir\n:inets.start()\n:ssl.start()\nurl = String.to_charlist(\"https://jsonplaceholder.typicode.com/posts\")\nheaders = []\nhttp_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]\n{:ok, {{_, status, _}, _, body}} = :httpc.request(:post, {url, headers, String.to_charlist(\"application/json\"), \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\"}, http_options, [body_format: :binary])\nIO.inspect(status)\nIO.puts(body)\n\n```\n\n**Lua · Lua-cURL**\n\n```lua\n-- Requires Lua-cURL; libcurl retains its default TLS verification.\nlocal curl = require('cURL')\nlocal response = {}\nlocal request = curl.easy {\n  url = \"https://jsonplaceholder.typicode.com/posts\",\n  customrequest = \"POST\",\n  httpheader = {\n    \"Content-Type: application/json\",\n  },\n  postfields = \"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\",\n  writefunction = function(chunk)\n    response[#response + 1] = chunk\n    return #chunk\n  end\n}\nrequest:perform()\nrequest:close()\nprint(table.concat(response))\n\n```\n\n**F# · HttpClient**\n\n```fsharp\nopen System.Net.Http\nopen System.Text\n\nuse client = new HttpClient()\nuse request = new HttpRequestMessage(HttpMethod(\"POST\"), \"https://jsonplaceholder.typicode.com/posts\")\nrequest.Content <- new StringContent(\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\", Encoding.UTF8)\nrequest.Content.Headers.ContentType <- System.Net.Http.Headers.MediaTypeHeaderValue.Parse(\"application/json\")\nuse response = client.SendAsync(request).GetAwaiter().GetResult()\nprintfn \"%s\" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n\n```\n\n**Visual Basic · HttpClient**\n\n```visualbasic\nImports System.Net.Http\nImports System.Text\n\nModule Example\n  Sub Main()\n    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod(\"POST\"), \"https://jsonplaceholder.typicode.com/posts\")\n      request.Content = New StringContent(\"{\" & ChrW(10) & \"  \"\"title\"\": \"\"Hello from Docsy\"\",\" & ChrW(10) & \"  \"\"body\"\": \"\"This request example comes from OpenAPI, not hardcoded UI.\"\",\" & ChrW(10) & \"  \"\"userId\"\": 1\" & ChrW(10) & \"}\", Encoding.UTF8)\n      request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(\"application/json\")\n      Using response = client.SendAsync(request).GetAwaiter().GetResult()\n        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n      End Using\n    End Using\n  End Sub\nEnd Module\n\n```\n\n**PowerShell · Invoke-RestMethod**\n\n```powershell\n$headers = @{\n}\n$response = Invoke-RestMethod -Method 'POST' -Uri 'https://jsonplaceholder.typicode.com/posts' -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes('{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}')) -ContentType 'application/json'\n$response | ConvertTo-Json -Depth 20\n\n```\n\n**R · httr**\n\n```r\nlibrary(httr)\n\nheaders <- setNames(c(\"application/json\"), c(\"Content-Type\"))\nresponse <- VERB(\"POST\", \"https://jsonplaceholder.typicode.com/posts\", add_headers(.headers = headers), body = charToRaw(enc2utf8(\"{\\n  \\\"title\\\": \\\"Hello from Docsy\\\",\\n  \\\"body\\\": \\\"This request example comes from OpenAPI, not hardcoded UI.\\\",\\n  \\\"userId\\\": 1\\n}\")))\nstop_for_status(response)\ncat(content(response, as = \"text\", encoding = \"UTF-8\"))\n\n```\n\n**Response** — `201`\n\n```json\n{\n  \"id\": 101,\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}\n```\n\n---\n\n### Get a post\n\nFetch one post by its ID. The generated curl command substitutes the path parameter example from this specification.\n\n**`GET`** `/posts/{id}`\n\n**Path parameters**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `id` | `integer` | ✓ | Existing post identifier. The request example uses post 1. |\n\n**Request**\n\n**cURL**\n\n```bash\ncurl --request GET \\\n  --url 'https://jsonplaceholder.typicode.com/posts/1'\n```\n\n**JavaScript · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"GET\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**TypeScript · fetch**\n\n```typescript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"GET\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Node.js · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"GET\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Python · requests**\n\n```python\nimport requests\n\nresponse = requests.request(\n    \"GET\",\n    \"https://jsonplaceholder.typicode.com/posts/1\",\n    headers={},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.text)\n\n```\n\n**Go · net/http**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://jsonplaceholder.typicode.com/posts/1\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n\n}\n```\n\n**Java · HttpClient**\n\n```java\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://jsonplaceholder.typicode.com/posts/1\"))\n    .method(\"GET\", HttpRequest.BodyPublishers.noBody())\n    .build();\nHttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());\nSystem.out.println(response.body());\n```\n\n**Kotlin · OkHttp**\n\n```kotlin\n// Requires OkHttp 4.x.\nimport okhttp3.OkHttpClient\nimport okhttp3.Request\nimport okhttp3.MediaType.Companion.toMediaType\nimport okhttp3.RequestBody.Companion.toRequestBody\n\nfun main() {\n  val request = Request.Builder()\n    .url(\"https://jsonplaceholder.typicode.com/posts/1\")\n    .method(\"GET\", null)\n    .build()\n  OkHttpClient().newCall(request).execute().use { response ->\n    println(response.body?.string())\n  }\n}\n\n```\n\n**C# · HttpClient**\n\n```csharp\nusing System.Net.Http.Headers;\nvar client = new HttpClient();\nvar request = new HttpRequestMessage\n{\n    Method = HttpMethod.Get,\n    RequestUri = new Uri(\"https://jsonplaceholder.typicode.com/posts/1\"),\n};\nusing (var response = await client.SendAsync(request))\n{\n    response.EnsureSuccessStatusCode();\n    var body = await response.Content.ReadAsStringAsync();\n    Console.WriteLine(body);\n}\n```\n\n**C · libcurl**\n\n```c\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"GET\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts/1\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**C++ · libcurl**\n\n```cpp\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"GET\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts/1\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**Rust · reqwest**\n\n```rust\n// Cargo: reqwest = \"0.12\", tokio = { version = \"1\", features = [\"full\"] }\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n    let response = reqwest::Client::new()\n        .request(reqwest::Method::from_bytes(\"GET\".as_bytes())?, \"https://jsonplaceholder.typicode.com/posts/1\")\n        .send().await?\n        .error_for_status()?;\n    println!(\"{}\", response.text().await?);\n    Ok(())\n}\n\n```\n\n**Swift · URLSession**\n\n```swift\nimport Foundation\n\nvar request = URLRequest(url: URL(string: \"https://jsonplaceholder.typicode.com/posts/1\")!)\nrequest.httpMethod = \"GET\"\nlet (data, _) = try await URLSession.shared.data(for: request)\nprint(String(decoding: data, as: UTF8.self))\n\n```\n\n**Objective-C · NSURLSession**\n\n```objectivec\n#import <Foundation/Foundation.h>\n\nint main(void) {\n  @autoreleasepool {\n    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@\"https://jsonplaceholder.typicode.com/posts/1\"]];\n    request.HTTPMethod = @\"GET\";\n    dispatch_semaphore_t done = dispatch_semaphore_create(0);\n    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {\n      if (error) NSLog(@\"%@\", error);\n      else NSLog(@\"%@\", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);\n      dispatch_semaphore_signal(done);\n    }] resume];\n    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);\n  }\n  return 0;\n}\n\n```\n\n**Dart · http**\n\n```dart\n// Requires package:http in pubspec.yaml.\nimport 'package:http/http.dart' as http;\n\nFuture<void> main() async {\n  final request = http.Request(\"GET\", Uri.parse(\"https://jsonplaceholder.typicode.com/posts/1\"));\n  request.headers.addAll({\n  });\n  final response = await request.send();\n  print(await response.stream.bytesToString());\n}\n\n```\n\n**PHP · cURL**\n\n```php\n<?php\n$curl = curl_init('https://jsonplaceholder.typicode.com/posts/1');\ncurl_setopt_array($curl, [\n    CURLOPT_CUSTOMREQUEST => 'GET',\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_TIMEOUT => 30,\n    CURLOPT_HTTPHEADER => [],\n]);\n$response = curl_exec($curl);\nif ($response === false) { throw new RuntimeException(curl_error($curl)); }\ncurl_close($curl);\necho $response;\n\n```\n\n**Ruby · Net::HTTP**\n\n```ruby\nrequire 'uri'\nrequire 'net/http'\n\nurl = URI(\"https://jsonplaceholder.typicode.com/posts/1\")\nhttp = Net::HTTP.new(url.host, url.port)\nhttp.use_ssl = url.scheme == 'https'\nrequest = Net::HTTPGenericRequest.new(\"GET\", false, true, url.request_uri, {})\nresponse = http.request(request)\nputs response.body\n\n```\n\n**Scala · Java HttpClient**\n\n```scala\nimport java.net.URI\nimport java.net.http.{HttpClient, HttpRequest, HttpResponse}\n\nobject Example extends App {\n  val request = HttpRequest.newBuilder(URI.create(\"https://jsonplaceholder.typicode.com/posts/1\"))\n    .method(\"GET\", HttpRequest.BodyPublishers.noBody())\n    .build()\n  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())\n  println(response.body())\n}\n\n```\n\n**Elixir · :httpc**\n\n```elixir\n:inets.start()\n:ssl.start()\nurl = String.to_charlist(\"https://jsonplaceholder.typicode.com/posts/1\")\nheaders = []\nhttp_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]\n{:ok, {{_, status, _}, _, body}} = :httpc.request(:get, {url, headers}, http_options, [body_format: :binary])\nIO.inspect(status)\nIO.puts(body)\n\n```\n\n**Lua · Lua-cURL**\n\n```lua\n-- Requires Lua-cURL; libcurl retains its default TLS verification.\nlocal curl = require('cURL')\nlocal response = {}\nlocal request = curl.easy {\n  url = \"https://jsonplaceholder.typicode.com/posts/1\",\n  customrequest = \"GET\",\n  httpheader = {\n  },\n  writefunction = function(chunk)\n    response[#response + 1] = chunk\n    return #chunk\n  end\n}\nrequest:perform()\nrequest:close()\nprint(table.concat(response))\n\n```\n\n**F# · HttpClient**\n\n```fsharp\nopen System.Net.Http\nopen System.Text\n\nuse client = new HttpClient()\nuse request = new HttpRequestMessage(HttpMethod(\"GET\"), \"https://jsonplaceholder.typicode.com/posts/1\")\nuse response = client.SendAsync(request).GetAwaiter().GetResult()\nprintfn \"%s\" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n\n```\n\n**Visual Basic · HttpClient**\n\n```visualbasic\nImports System.Net.Http\nImports System.Text\n\nModule Example\n  Sub Main()\n    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod(\"GET\"), \"https://jsonplaceholder.typicode.com/posts/1\")\n      Using response = client.SendAsync(request).GetAwaiter().GetResult()\n        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n      End Using\n    End Using\n  End Sub\nEnd Module\n\n```\n\n**PowerShell · Invoke-RestMethod**\n\n```powershell\n$headers = @{\n}\n$response = Invoke-RestMethod -Method 'GET' -Uri 'https://jsonplaceholder.typicode.com/posts/1' -Headers $headers\n$response | ConvertTo-Json -Depth 20\n\n```\n\n**R · httr**\n\n```r\nlibrary(httr)\n\nheaders <- setNames(c(), c())\nresponse <- VERB(\"GET\", \"https://jsonplaceholder.typicode.com/posts/1\", add_headers(.headers = headers))\nstop_for_status(response)\ncat(content(response, as = \"text\", encoding = \"UTF-8\"))\n\n```\n\n**Response** — `200`\n\n```json\n{\n  \"id\": 1,\n  \"userId\": 1,\n  \"title\": \"An example post\",\n  \"body\": \"Example response content. Live post text can differ.\"\n}\n```\n\n---\n\n### Replace a post\n\nSend all writable fields in a JSON body. The replacement is simulated and is not persisted.\n\n**`PUT`** `/posts/{id}`\n\n**Path parameters**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `id` | `integer` | ✓ | Existing post identifier. The request example uses post 1. |\n\n**Body**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `title` | `string` | ✓ | The post title. |\n\n| `body` | `string` | ✓ | Plain-text content of the post. |\n\n| `userId` | `integer` | ✓ | User associated with the post. |\n\n**Request**\n\n**cURL**\n\n```bash\ncurl --request PUT \\\n  --url 'https://jsonplaceholder.typicode.com/posts/1' \\\n  --header 'Content-Type: application/json' \\\n  --data '{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}'\n```\n\n**JavaScript · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"PUT\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**TypeScript · fetch**\n\n```typescript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"PUT\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Node.js · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"PUT\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Python · requests**\n\n```python\nimport requests\n\nresponse = requests.request(\n    \"PUT\",\n    \"https://jsonplaceholder.typicode.com/posts/1\",\n    headers={\"Content-Type\": \"application/json\"},\n    data=\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\".encode(\"utf-8\"),\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.text)\n\n```\n\n**Go · net/http**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://jsonplaceholder.typicode.com/posts/1\"\n\n\tpayload := strings.NewReader(\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\")\n\n\treq, _ := http.NewRequest(\"PUT\", url, payload)\n\n\treq.Header.Add(\"Content-Type\", \"application/json\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n\n}\n```\n\n**Java · HttpClient**\n\n```java\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://jsonplaceholder.typicode.com/posts/1\"))\n    .header(\"Content-Type\", \"application/json\")\n    .method(\"PUT\", HttpRequest.BodyPublishers.ofString(\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\"))\n    .build();\nHttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());\nSystem.out.println(response.body());\n```\n\n**Kotlin · OkHttp**\n\n```kotlin\n// Requires OkHttp 4.x.\nimport okhttp3.OkHttpClient\nimport okhttp3.Request\nimport okhttp3.MediaType.Companion.toMediaType\nimport okhttp3.RequestBody.Companion.toRequestBody\n\nfun main() {\n  val request = Request.Builder()\n    .url(\"https://jsonplaceholder.typicode.com/posts/1\")\n    .method(\"PUT\", \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\".toRequestBody(\"application/json\".toMediaType()))\n    .addHeader(\"Content-Type\", \"application/json\")\n    .build()\n  OkHttpClient().newCall(request).execute().use { response ->\n    println(response.body?.string())\n  }\n}\n\n```\n\n**C# · HttpClient**\n\n```csharp\nusing System.Net.Http.Headers;\nvar client = new HttpClient();\nvar request = new HttpRequestMessage\n{\n    Method = HttpMethod.Put,\n    RequestUri = new Uri(\"https://jsonplaceholder.typicode.com/posts/1\"),\n    Content = new StringContent(\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\")\n    {\n        Headers =\n        {\n            ContentType = new MediaTypeHeaderValue(\"application/json\")\n        }\n    }\n};\nusing (var response = await client.SendAsync(request))\n{\n    response.EnsureSuccessStatusCode();\n    var body = await response.Content.ReadAsStringAsync();\n    Console.WriteLine(body);\n}\n```\n\n**C · libcurl**\n\n```c\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"PUT\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts/1\");\n\nstruct curl_slist *headers = NULL;\nheaders = curl_slist_append(headers, \"Content-Type: application/json\");\ncurl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);\n\ncurl_easy_setopt(hnd, CURLOPT_POSTFIELDS, \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**C++ · libcurl**\n\n```cpp\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"PUT\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts/1\");\n\nstruct curl_slist *headers = NULL;\nheaders = curl_slist_append(headers, \"Content-Type: application/json\");\ncurl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);\n\ncurl_easy_setopt(hnd, CURLOPT_POSTFIELDS, \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**Rust · reqwest**\n\n```rust\n// Cargo: reqwest = \"0.12\", tokio = { version = \"1\", features = [\"full\"] }\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n    let response = reqwest::Client::new()\n        .request(reqwest::Method::from_bytes(\"PUT\".as_bytes())?, \"https://jsonplaceholder.typicode.com/posts/1\")\n        .header(\"Content-Type\", \"application/json\")\n        .body(\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\")\n        .send().await?\n        .error_for_status()?;\n    println!(\"{}\", response.text().await?);\n    Ok(())\n}\n\n```\n\n**Swift · URLSession**\n\n```swift\nimport Foundation\n\nvar request = URLRequest(url: URL(string: \"https://jsonplaceholder.typicode.com/posts/1\")!)\nrequest.httpMethod = \"PUT\"\nrequest.setValue(\"application/json\", forHTTPHeaderField: \"Content-Type\")\nrequest.httpBody = Data(\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\".utf8)\nlet (data, _) = try await URLSession.shared.data(for: request)\nprint(String(decoding: data, as: UTF8.self))\n\n```\n\n**Objective-C · NSURLSession**\n\n```objectivec\n#import <Foundation/Foundation.h>\n\nint main(void) {\n  @autoreleasepool {\n    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@\"https://jsonplaceholder.typicode.com/posts/1\"]];\n    request.HTTPMethod = @\"PUT\";\n    [request setValue:@\"application/json\" forHTTPHeaderField:@\"Content-Type\"];\n    request.HTTPBody = [@\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\" dataUsingEncoding:NSUTF8StringEncoding];\n    dispatch_semaphore_t done = dispatch_semaphore_create(0);\n    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {\n      if (error) NSLog(@\"%@\", error);\n      else NSLog(@\"%@\", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);\n      dispatch_semaphore_signal(done);\n    }] resume];\n    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);\n  }\n  return 0;\n}\n\n```\n\n**Dart · http**\n\n```dart\n// Requires package:http in pubspec.yaml.\nimport 'package:http/http.dart' as http;\n\nFuture<void> main() async {\n  final request = http.Request(\"PUT\", Uri.parse(\"https://jsonplaceholder.typicode.com/posts/1\"));\n  request.headers.addAll({\n    \"Content-Type\": \"application/json\",\n  });\n  request.body = \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\";\n  final response = await request.send();\n  print(await response.stream.bytesToString());\n}\n\n```\n\n**PHP · cURL**\n\n```php\n<?php\n$curl = curl_init('https://jsonplaceholder.typicode.com/posts/1');\ncurl_setopt_array($curl, [\n    CURLOPT_CUSTOMREQUEST => 'PUT',\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_TIMEOUT => 30,\n    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],\n    CURLOPT_POSTFIELDS => '{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}',\n]);\n$response = curl_exec($curl);\nif ($response === false) { throw new RuntimeException(curl_error($curl)); }\ncurl_close($curl);\necho $response;\n\n```\n\n**Ruby · Net::HTTP**\n\n```ruby\nrequire 'uri'\nrequire 'net/http'\n\nurl = URI(\"https://jsonplaceholder.typicode.com/posts/1\")\nhttp = Net::HTTP.new(url.host, url.port)\nhttp.use_ssl = url.scheme == 'https'\nrequest = Net::HTTPGenericRequest.new(\"PUT\", true, true, url.request_uri, {\"Content-Type\" => \"application/json\"})\nrequest.body = \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\"\nresponse = http.request(request)\nputs response.body\n\n```\n\n**Scala · Java HttpClient**\n\n```scala\nimport java.net.URI\nimport java.net.http.{HttpClient, HttpRequest, HttpResponse}\n\nobject Example extends App {\n  val request = HttpRequest.newBuilder(URI.create(\"https://jsonplaceholder.typicode.com/posts/1\"))\n    .header(\"Content-Type\", \"application/json\")\n    .method(\"PUT\", HttpRequest.BodyPublishers.ofString(\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\"))\n    .build()\n  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())\n  println(response.body())\n}\n\n```\n\n**Elixir · :httpc**\n\n```elixir\n:inets.start()\n:ssl.start()\nurl = String.to_charlist(\"https://jsonplaceholder.typicode.com/posts/1\")\nheaders = []\nhttp_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]\n{:ok, {{_, status, _}, _, body}} = :httpc.request(:put, {url, headers, String.to_charlist(\"application/json\"), \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\"}, http_options, [body_format: :binary])\nIO.inspect(status)\nIO.puts(body)\n\n```\n\n**Lua · Lua-cURL**\n\n```lua\n-- Requires Lua-cURL; libcurl retains its default TLS verification.\nlocal curl = require('cURL')\nlocal response = {}\nlocal request = curl.easy {\n  url = \"https://jsonplaceholder.typicode.com/posts/1\",\n  customrequest = \"PUT\",\n  httpheader = {\n    \"Content-Type: application/json\",\n  },\n  postfields = \"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\",\n  writefunction = function(chunk)\n    response[#response + 1] = chunk\n    return #chunk\n  end\n}\nrequest:perform()\nrequest:close()\nprint(table.concat(response))\n\n```\n\n**F# · HttpClient**\n\n```fsharp\nopen System.Net.Http\nopen System.Text\n\nuse client = new HttpClient()\nuse request = new HttpRequestMessage(HttpMethod(\"PUT\"), \"https://jsonplaceholder.typicode.com/posts/1\")\nrequest.Content <- new StringContent(\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\", Encoding.UTF8)\nrequest.Content.Headers.ContentType <- System.Net.Http.Headers.MediaTypeHeaderValue.Parse(\"application/json\")\nuse response = client.SendAsync(request).GetAwaiter().GetResult()\nprintfn \"%s\" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n\n```\n\n**Visual Basic · HttpClient**\n\n```visualbasic\nImports System.Net.Http\nImports System.Text\n\nModule Example\n  Sub Main()\n    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod(\"PUT\"), \"https://jsonplaceholder.typicode.com/posts/1\")\n      request.Content = New StringContent(\"{\" & ChrW(10) & \"  \"\"title\"\": \"\"A replacement post\"\",\" & ChrW(10) & \"  \"\"body\"\": \"\"Replace the complete writable post content.\"\",\" & ChrW(10) & \"  \"\"userId\"\": 1\" & ChrW(10) & \"}\", Encoding.UTF8)\n      request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(\"application/json\")\n      Using response = client.SendAsync(request).GetAwaiter().GetResult()\n        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n      End Using\n    End Using\n  End Sub\nEnd Module\n\n```\n\n**PowerShell · Invoke-RestMethod**\n\n```powershell\n$headers = @{\n}\n$response = Invoke-RestMethod -Method 'PUT' -Uri 'https://jsonplaceholder.typicode.com/posts/1' -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes('{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}')) -ContentType 'application/json'\n$response | ConvertTo-Json -Depth 20\n\n```\n\n**R · httr**\n\n```r\nlibrary(httr)\n\nheaders <- setNames(c(\"application/json\"), c(\"Content-Type\"))\nresponse <- VERB(\"PUT\", \"https://jsonplaceholder.typicode.com/posts/1\", add_headers(.headers = headers), body = charToRaw(enc2utf8(\"{\\n  \\\"title\\\": \\\"A replacement post\\\",\\n  \\\"body\\\": \\\"Replace the complete writable post content.\\\",\\n  \\\"userId\\\": 1\\n}\")))\nstop_for_status(response)\ncat(content(response, as = \"text\", encoding = \"UTF-8\"))\n\n```\n\n**Response** — `200`\n\n```json\n{\n  \"id\": 1,\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}\n```\n\n---\n\n### Update a post title\n\nSend only the fields to change. This request demonstrates a partial JSON body; changes are not persisted.\n\n**`PATCH`** `/posts/{id}`\n\n**Path parameters**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `id` | `integer` | ✓ | Existing post identifier. The request example uses post 1. |\n\n**Body**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `title` | `string` | ✓ | Replacement title; other post fields remain unchanged. |\n\n**Request**\n\n**cURL**\n\n```bash\ncurl --request PATCH \\\n  --url 'https://jsonplaceholder.typicode.com/posts/1' \\\n  --header 'Content-Type: application/json' \\\n  --data '{\n  \"title\": \"An updated title from Docsy\"\n}'\n```\n\n**JavaScript · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"PATCH\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**TypeScript · fetch**\n\n```typescript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"PATCH\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Node.js · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"PATCH\",\n  headers: {\n    \"Content-Type\": \"application/json\"\n  },\n  body: \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\",\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Python · requests**\n\n```python\nimport requests\n\nresponse = requests.request(\n    \"PATCH\",\n    \"https://jsonplaceholder.typicode.com/posts/1\",\n    headers={\"Content-Type\": \"application/json\"},\n    data=\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\".encode(\"utf-8\"),\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.text)\n\n```\n\n**Go · net/http**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://jsonplaceholder.typicode.com/posts/1\"\n\n\tpayload := strings.NewReader(\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\")\n\n\treq, _ := http.NewRequest(\"PATCH\", url, payload)\n\n\treq.Header.Add(\"Content-Type\", \"application/json\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n\n}\n```\n\n**Java · HttpClient**\n\n```java\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://jsonplaceholder.typicode.com/posts/1\"))\n    .header(\"Content-Type\", \"application/json\")\n    .method(\"PATCH\", HttpRequest.BodyPublishers.ofString(\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\"))\n    .build();\nHttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());\nSystem.out.println(response.body());\n```\n\n**Kotlin · OkHttp**\n\n```kotlin\n// Requires OkHttp 4.x.\nimport okhttp3.OkHttpClient\nimport okhttp3.Request\nimport okhttp3.MediaType.Companion.toMediaType\nimport okhttp3.RequestBody.Companion.toRequestBody\n\nfun main() {\n  val request = Request.Builder()\n    .url(\"https://jsonplaceholder.typicode.com/posts/1\")\n    .method(\"PATCH\", \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\".toRequestBody(\"application/json\".toMediaType()))\n    .addHeader(\"Content-Type\", \"application/json\")\n    .build()\n  OkHttpClient().newCall(request).execute().use { response ->\n    println(response.body?.string())\n  }\n}\n\n```\n\n**C# · HttpClient**\n\n```csharp\nusing System.Net.Http.Headers;\nvar client = new HttpClient();\nvar request = new HttpRequestMessage\n{\n    Method = HttpMethod.Patch,\n    RequestUri = new Uri(\"https://jsonplaceholder.typicode.com/posts/1\"),\n    Content = new StringContent(\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\")\n    {\n        Headers =\n        {\n            ContentType = new MediaTypeHeaderValue(\"application/json\")\n        }\n    }\n};\nusing (var response = await client.SendAsync(request))\n{\n    response.EnsureSuccessStatusCode();\n    var body = await response.Content.ReadAsStringAsync();\n    Console.WriteLine(body);\n}\n```\n\n**C · libcurl**\n\n```c\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"PATCH\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts/1\");\n\nstruct curl_slist *headers = NULL;\nheaders = curl_slist_append(headers, \"Content-Type: application/json\");\ncurl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);\n\ncurl_easy_setopt(hnd, CURLOPT_POSTFIELDS, \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**C++ · libcurl**\n\n```cpp\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"PATCH\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts/1\");\n\nstruct curl_slist *headers = NULL;\nheaders = curl_slist_append(headers, \"Content-Type: application/json\");\ncurl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);\n\ncurl_easy_setopt(hnd, CURLOPT_POSTFIELDS, \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**Rust · reqwest**\n\n```rust\n// Cargo: reqwest = \"0.12\", tokio = { version = \"1\", features = [\"full\"] }\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n    let response = reqwest::Client::new()\n        .request(reqwest::Method::from_bytes(\"PATCH\".as_bytes())?, \"https://jsonplaceholder.typicode.com/posts/1\")\n        .header(\"Content-Type\", \"application/json\")\n        .body(\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\")\n        .send().await?\n        .error_for_status()?;\n    println!(\"{}\", response.text().await?);\n    Ok(())\n}\n\n```\n\n**Swift · URLSession**\n\n```swift\nimport Foundation\n\nvar request = URLRequest(url: URL(string: \"https://jsonplaceholder.typicode.com/posts/1\")!)\nrequest.httpMethod = \"PATCH\"\nrequest.setValue(\"application/json\", forHTTPHeaderField: \"Content-Type\")\nrequest.httpBody = Data(\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\".utf8)\nlet (data, _) = try await URLSession.shared.data(for: request)\nprint(String(decoding: data, as: UTF8.self))\n\n```\n\n**Objective-C · NSURLSession**\n\n```objectivec\n#import <Foundation/Foundation.h>\n\nint main(void) {\n  @autoreleasepool {\n    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@\"https://jsonplaceholder.typicode.com/posts/1\"]];\n    request.HTTPMethod = @\"PATCH\";\n    [request setValue:@\"application/json\" forHTTPHeaderField:@\"Content-Type\"];\n    request.HTTPBody = [@\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\" dataUsingEncoding:NSUTF8StringEncoding];\n    dispatch_semaphore_t done = dispatch_semaphore_create(0);\n    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {\n      if (error) NSLog(@\"%@\", error);\n      else NSLog(@\"%@\", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);\n      dispatch_semaphore_signal(done);\n    }] resume];\n    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);\n  }\n  return 0;\n}\n\n```\n\n**Dart · http**\n\n```dart\n// Requires package:http in pubspec.yaml.\nimport 'package:http/http.dart' as http;\n\nFuture<void> main() async {\n  final request = http.Request(\"PATCH\", Uri.parse(\"https://jsonplaceholder.typicode.com/posts/1\"));\n  request.headers.addAll({\n    \"Content-Type\": \"application/json\",\n  });\n  request.body = \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\";\n  final response = await request.send();\n  print(await response.stream.bytesToString());\n}\n\n```\n\n**PHP · cURL**\n\n```php\n<?php\n$curl = curl_init('https://jsonplaceholder.typicode.com/posts/1');\ncurl_setopt_array($curl, [\n    CURLOPT_CUSTOMREQUEST => 'PATCH',\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_TIMEOUT => 30,\n    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],\n    CURLOPT_POSTFIELDS => '{\n  \"title\": \"An updated title from Docsy\"\n}',\n]);\n$response = curl_exec($curl);\nif ($response === false) { throw new RuntimeException(curl_error($curl)); }\ncurl_close($curl);\necho $response;\n\n```\n\n**Ruby · Net::HTTP**\n\n```ruby\nrequire 'uri'\nrequire 'net/http'\n\nurl = URI(\"https://jsonplaceholder.typicode.com/posts/1\")\nhttp = Net::HTTP.new(url.host, url.port)\nhttp.use_ssl = url.scheme == 'https'\nrequest = Net::HTTPGenericRequest.new(\"PATCH\", true, true, url.request_uri, {\"Content-Type\" => \"application/json\"})\nrequest.body = \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\"\nresponse = http.request(request)\nputs response.body\n\n```\n\n**Scala · Java HttpClient**\n\n```scala\nimport java.net.URI\nimport java.net.http.{HttpClient, HttpRequest, HttpResponse}\n\nobject Example extends App {\n  val request = HttpRequest.newBuilder(URI.create(\"https://jsonplaceholder.typicode.com/posts/1\"))\n    .header(\"Content-Type\", \"application/json\")\n    .method(\"PATCH\", HttpRequest.BodyPublishers.ofString(\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\"))\n    .build()\n  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())\n  println(response.body())\n}\n\n```\n\n**Elixir · :httpc**\n\n```elixir\n:inets.start()\n:ssl.start()\nurl = String.to_charlist(\"https://jsonplaceholder.typicode.com/posts/1\")\nheaders = []\nhttp_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]\n{:ok, {{_, status, _}, _, body}} = :httpc.request(:patch, {url, headers, String.to_charlist(\"application/json\"), \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\"}, http_options, [body_format: :binary])\nIO.inspect(status)\nIO.puts(body)\n\n```\n\n**Lua · Lua-cURL**\n\n```lua\n-- Requires Lua-cURL; libcurl retains its default TLS verification.\nlocal curl = require('cURL')\nlocal response = {}\nlocal request = curl.easy {\n  url = \"https://jsonplaceholder.typicode.com/posts/1\",\n  customrequest = \"PATCH\",\n  httpheader = {\n    \"Content-Type: application/json\",\n  },\n  postfields = \"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\",\n  writefunction = function(chunk)\n    response[#response + 1] = chunk\n    return #chunk\n  end\n}\nrequest:perform()\nrequest:close()\nprint(table.concat(response))\n\n```\n\n**F# · HttpClient**\n\n```fsharp\nopen System.Net.Http\nopen System.Text\n\nuse client = new HttpClient()\nuse request = new HttpRequestMessage(HttpMethod(\"PATCH\"), \"https://jsonplaceholder.typicode.com/posts/1\")\nrequest.Content <- new StringContent(\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\", Encoding.UTF8)\nrequest.Content.Headers.ContentType <- System.Net.Http.Headers.MediaTypeHeaderValue.Parse(\"application/json\")\nuse response = client.SendAsync(request).GetAwaiter().GetResult()\nprintfn \"%s\" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n\n```\n\n**Visual Basic · HttpClient**\n\n```visualbasic\nImports System.Net.Http\nImports System.Text\n\nModule Example\n  Sub Main()\n    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod(\"PATCH\"), \"https://jsonplaceholder.typicode.com/posts/1\")\n      request.Content = New StringContent(\"{\" & ChrW(10) & \"  \"\"title\"\": \"\"An updated title from Docsy\"\"\" & ChrW(10) & \"}\", Encoding.UTF8)\n      request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(\"application/json\")\n      Using response = client.SendAsync(request).GetAwaiter().GetResult()\n        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n      End Using\n    End Using\n  End Sub\nEnd Module\n\n```\n\n**PowerShell · Invoke-RestMethod**\n\n```powershell\n$headers = @{\n}\n$response = Invoke-RestMethod -Method 'PATCH' -Uri 'https://jsonplaceholder.typicode.com/posts/1' -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes('{\n  \"title\": \"An updated title from Docsy\"\n}')) -ContentType 'application/json'\n$response | ConvertTo-Json -Depth 20\n\n```\n\n**R · httr**\n\n```r\nlibrary(httr)\n\nheaders <- setNames(c(\"application/json\"), c(\"Content-Type\"))\nresponse <- VERB(\"PATCH\", \"https://jsonplaceholder.typicode.com/posts/1\", add_headers(.headers = headers), body = charToRaw(enc2utf8(\"{\\n  \\\"title\\\": \\\"An updated title from Docsy\\\"\\n}\")))\nstop_for_status(response)\ncat(content(response, as = \"text\", encoding = \"UTF-8\"))\n\n```\n\n**Response** — `200`\n\n```json\n{\n  \"id\": 1,\n  \"userId\": 1,\n  \"title\": \"An updated title from Docsy\",\n  \"body\": \"Original post body, unchanged by this PATCH.\"\n}\n```\n\n---\n\n### Delete a post\n\nSimulate deletion of a post. JSONPlaceholder leaves the original post available; this request does not delete persistent data.\n\n**`DELETE`** `/posts/{id}`\n\n**Path parameters**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `id` | `integer` | ✓ | Existing post identifier. The request example uses post 1. |\n\n**Request**\n\n**cURL**\n\n```bash\ncurl --request DELETE \\\n  --url 'https://jsonplaceholder.typicode.com/posts/1'\n```\n\n**JavaScript · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"DELETE\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**TypeScript · fetch**\n\n```typescript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"DELETE\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Node.js · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/posts/1\", {\n  method: \"DELETE\",\n  headers: {},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.text());\n\n```\n\n**Python · requests**\n\n```python\nimport requests\n\nresponse = requests.request(\n    \"DELETE\",\n    \"https://jsonplaceholder.typicode.com/posts/1\",\n    headers={},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.text)\n\n```\n\n**Go · net/http**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://jsonplaceholder.typicode.com/posts/1\"\n\n\treq, _ := http.NewRequest(\"DELETE\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n\n}\n```\n\n**Java · HttpClient**\n\n```java\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://jsonplaceholder.typicode.com/posts/1\"))\n    .method(\"DELETE\", HttpRequest.BodyPublishers.noBody())\n    .build();\nHttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());\nSystem.out.println(response.body());\n```\n\n**Kotlin · OkHttp**\n\n```kotlin\n// Requires OkHttp 4.x.\nimport okhttp3.OkHttpClient\nimport okhttp3.Request\nimport okhttp3.MediaType.Companion.toMediaType\nimport okhttp3.RequestBody.Companion.toRequestBody\n\nfun main() {\n  val request = Request.Builder()\n    .url(\"https://jsonplaceholder.typicode.com/posts/1\")\n    .method(\"DELETE\", null)\n    .build()\n  OkHttpClient().newCall(request).execute().use { response ->\n    println(response.body?.string())\n  }\n}\n\n```\n\n**C# · HttpClient**\n\n```csharp\nusing System.Net.Http.Headers;\nvar client = new HttpClient();\nvar request = new HttpRequestMessage\n{\n    Method = HttpMethod.Delete,\n    RequestUri = new Uri(\"https://jsonplaceholder.typicode.com/posts/1\"),\n};\nusing (var response = await client.SendAsync(request))\n{\n    response.EnsureSuccessStatusCode();\n    var body = await response.Content.ReadAsStringAsync();\n    Console.WriteLine(body);\n}\n```\n\n**C · libcurl**\n\n```c\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"DELETE\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts/1\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**C++ · libcurl**\n\n```cpp\nCURL *hnd = curl_easy_init();\n\ncurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, \"DELETE\");\ncurl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);\ncurl_easy_setopt(hnd, CURLOPT_URL, \"https://jsonplaceholder.typicode.com/posts/1\");\n\nCURLcode ret = curl_easy_perform(hnd);\n```\n\n**Rust · reqwest**\n\n```rust\n// Cargo: reqwest = \"0.12\", tokio = { version = \"1\", features = [\"full\"] }\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n    let response = reqwest::Client::new()\n        .request(reqwest::Method::from_bytes(\"DELETE\".as_bytes())?, \"https://jsonplaceholder.typicode.com/posts/1\")\n        .send().await?\n        .error_for_status()?;\n    println!(\"{}\", response.text().await?);\n    Ok(())\n}\n\n```\n\n**Swift · URLSession**\n\n```swift\nimport Foundation\n\nvar request = URLRequest(url: URL(string: \"https://jsonplaceholder.typicode.com/posts/1\")!)\nrequest.httpMethod = \"DELETE\"\nlet (data, _) = try await URLSession.shared.data(for: request)\nprint(String(decoding: data, as: UTF8.self))\n\n```\n\n**Objective-C · NSURLSession**\n\n```objectivec\n#import <Foundation/Foundation.h>\n\nint main(void) {\n  @autoreleasepool {\n    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@\"https://jsonplaceholder.typicode.com/posts/1\"]];\n    request.HTTPMethod = @\"DELETE\";\n    dispatch_semaphore_t done = dispatch_semaphore_create(0);\n    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {\n      if (error) NSLog(@\"%@\", error);\n      else NSLog(@\"%@\", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);\n      dispatch_semaphore_signal(done);\n    }] resume];\n    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);\n  }\n  return 0;\n}\n\n```\n\n**Dart · http**\n\n```dart\n// Requires package:http in pubspec.yaml.\nimport 'package:http/http.dart' as http;\n\nFuture<void> main() async {\n  final request = http.Request(\"DELETE\", Uri.parse(\"https://jsonplaceholder.typicode.com/posts/1\"));\n  request.headers.addAll({\n  });\n  final response = await request.send();\n  print(await response.stream.bytesToString());\n}\n\n```\n\n**PHP · cURL**\n\n```php\n<?php\n$curl = curl_init('https://jsonplaceholder.typicode.com/posts/1');\ncurl_setopt_array($curl, [\n    CURLOPT_CUSTOMREQUEST => 'DELETE',\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_TIMEOUT => 30,\n    CURLOPT_HTTPHEADER => [],\n]);\n$response = curl_exec($curl);\nif ($response === false) { throw new RuntimeException(curl_error($curl)); }\ncurl_close($curl);\necho $response;\n\n```\n\n**Ruby · Net::HTTP**\n\n```ruby\nrequire 'uri'\nrequire 'net/http'\n\nurl = URI(\"https://jsonplaceholder.typicode.com/posts/1\")\nhttp = Net::HTTP.new(url.host, url.port)\nhttp.use_ssl = url.scheme == 'https'\nrequest = Net::HTTPGenericRequest.new(\"DELETE\", false, true, url.request_uri, {})\nresponse = http.request(request)\nputs response.body\n\n```\n\n**Scala · Java HttpClient**\n\n```scala\nimport java.net.URI\nimport java.net.http.{HttpClient, HttpRequest, HttpResponse}\n\nobject Example extends App {\n  val request = HttpRequest.newBuilder(URI.create(\"https://jsonplaceholder.typicode.com/posts/1\"))\n    .method(\"DELETE\", HttpRequest.BodyPublishers.noBody())\n    .build()\n  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())\n  println(response.body())\n}\n\n```\n\n**Elixir · :httpc**\n\n```elixir\n:inets.start()\n:ssl.start()\nurl = String.to_charlist(\"https://jsonplaceholder.typicode.com/posts/1\")\nheaders = []\nhttp_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]\n{:ok, {{_, status, _}, _, body}} = :httpc.request(:delete, {url, headers}, http_options, [body_format: :binary])\nIO.inspect(status)\nIO.puts(body)\n\n```\n\n**Lua · Lua-cURL**\n\n```lua\n-- Requires Lua-cURL; libcurl retains its default TLS verification.\nlocal curl = require('cURL')\nlocal response = {}\nlocal request = curl.easy {\n  url = \"https://jsonplaceholder.typicode.com/posts/1\",\n  customrequest = \"DELETE\",\n  httpheader = {\n  },\n  writefunction = function(chunk)\n    response[#response + 1] = chunk\n    return #chunk\n  end\n}\nrequest:perform()\nrequest:close()\nprint(table.concat(response))\n\n```\n\n**F# · HttpClient**\n\n```fsharp\nopen System.Net.Http\nopen System.Text\n\nuse client = new HttpClient()\nuse request = new HttpRequestMessage(HttpMethod(\"DELETE\"), \"https://jsonplaceholder.typicode.com/posts/1\")\nuse response = client.SendAsync(request).GetAwaiter().GetResult()\nprintfn \"%s\" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n\n```\n\n**Visual Basic · HttpClient**\n\n```visualbasic\nImports System.Net.Http\nImports System.Text\n\nModule Example\n  Sub Main()\n    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod(\"DELETE\"), \"https://jsonplaceholder.typicode.com/posts/1\")\n      Using response = client.SendAsync(request).GetAwaiter().GetResult()\n        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())\n      End Using\n    End Using\n  End Sub\nEnd Module\n\n```\n\n**PowerShell · Invoke-RestMethod**\n\n```powershell\n$headers = @{\n}\n$response = Invoke-RestMethod -Method 'DELETE' -Uri 'https://jsonplaceholder.typicode.com/posts/1' -Headers $headers\n$response | ConvertTo-Json -Depth 20\n\n```\n\n**R · httr**\n\n```r\nlibrary(httr)\n\nheaders <- setNames(c(), c())\nresponse <- VERB(\"DELETE\", \"https://jsonplaceholder.typicode.com/posts/1\", add_headers(.headers = headers))\nstop_for_status(response)\ncat(content(response, as = \"text\", encoding = \"UTF-8\"))\n\n```\n\n**Response** — `200`\n\n```json\n{}\n```\n"}