# Posts · OpenAPI sample

Public JSONPlaceholder requests, generated from a local OpenAPI file. Copy GET, POST, PUT, PATCH, and DELETE examples. Writes are simulated and are not persisted.

> Source: https://appgram.github.io/docsy/versions/current/fr/api/posts  
> Endpoints: 6  
> API version: v1.0.0

See [How this OpenAPI sample works](/docsy/versions/current/fr/guides/tutorials/openapi-ingestion) for the base setup.

### List posts

Read posts, optionally filtering by user. The sample query uses `userId=1`; no authentication is required.

**`GET`** `/posts`

**Query parameters**

| Name | Type | Required | Description |

| --- | --- | --- | --- |

| `userId` | `integer` |  | Return posts belonging to this user. Omit the parameter to list all posts. |

**Request**

**cURL**

```bash
curl --request GET \
  --url 'https://jsonplaceholder.typicode.com/posts?userId=1'
```

**JavaScript · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts?userId=1", {
  method: "GET",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**TypeScript · fetch**

```typescript
const response = await fetch("https://jsonplaceholder.typicode.com/posts?userId=1", {
  method: "GET",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Node.js · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts?userId=1", {
  method: "GET",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Python · requests**

```python
import requests

response = requests.request(
    "GET",
    "https://jsonplaceholder.typicode.com/posts?userId=1",
    headers={},
    timeout=30,
)
response.raise_for_status()
print(response.text)

```

**Go · net/http**

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://jsonplaceholder.typicode.com/posts?userId=1"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

**Java · HttpClient**

```java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://jsonplaceholder.typicode.com/posts?userId=1"))
    .method("GET", HttpRequest.BodyPublishers.noBody())
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**Kotlin · OkHttp**

```kotlin
// Requires OkHttp 4.x.
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody

fun main() {
  val request = Request.Builder()
    .url("https://jsonplaceholder.typicode.com/posts?userId=1")
    .method("GET", null)
    .build()
  OkHttpClient().newCall(request).execute().use { response ->
    println(response.body?.string())
  }
}

```

**C# · HttpClient**

```csharp
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new Uri("https://jsonplaceholder.typicode.com/posts?userId=1"),
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

**C · libcurl**

```c
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts?userId=1");

CURLcode ret = curl_easy_perform(hnd);
```

**C++ · libcurl**

```cpp
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts?userId=1");

CURLcode ret = curl_easy_perform(hnd);
```

**Rust · reqwest**

```rust
// Cargo: reqwest = "0.12", tokio = { version = "1", features = ["full"] }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::Client::new()
        .request(reqwest::Method::from_bytes("GET".as_bytes())?, "https://jsonplaceholder.typicode.com/posts?userId=1")
        .send().await?
        .error_for_status()?;
    println!("{}", response.text().await?);
    Ok(())
}

```

**Swift · URLSession**

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/posts?userId=1")!)
request.httpMethod = "GET"
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))

```

**Objective-C · NSURLSession**

```objectivec
#import <Foundation/Foundation.h>

int main(void) {
  @autoreleasepool {
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://jsonplaceholder.typicode.com/posts?userId=1"]];
    request.HTTPMethod = @"GET";
    dispatch_semaphore_t done = dispatch_semaphore_create(0);
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      if (error) NSLog(@"%@", error);
      else NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
      dispatch_semaphore_signal(done);
    }] resume];
    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
  }
  return 0;
}

```

**Dart · http**

```dart
// Requires package:http in pubspec.yaml.
import 'package:http/http.dart' as http;

Future<void> main() async {
  final request = http.Request("GET", Uri.parse("https://jsonplaceholder.typicode.com/posts?userId=1"));
  request.headers.addAll({
  });
  final response = await request.send();
  print(await response.stream.bytesToString());
}

```

**PHP · cURL**

```php
<?php
$curl = curl_init('https://jsonplaceholder.typicode.com/posts?userId=1');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [],
]);
$response = curl_exec($curl);
if ($response === false) { throw new RuntimeException(curl_error($curl)); }
curl_close($curl);
echo $response;

```

**Ruby · Net::HTTP**

```ruby
require 'uri'
require 'net/http'

url = URI("https://jsonplaceholder.typicode.com/posts?userId=1")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTPGenericRequest.new("GET", false, true, url.request_uri, {})
response = http.request(request)
puts response.body

```

**Scala · Java HttpClient**

```scala
import java.net.URI
import java.net.http.{HttpClient, HttpRequest, HttpResponse}

object Example extends App {
  val request = HttpRequest.newBuilder(URI.create("https://jsonplaceholder.typicode.com/posts?userId=1"))
    .method("GET", HttpRequest.BodyPublishers.noBody())
    .build()
  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())
  println(response.body())
}

```

**Elixir · :httpc**

```elixir
:inets.start()
:ssl.start()
url = String.to_charlist("https://jsonplaceholder.typicode.com/posts?userId=1")
headers = []
http_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]
{:ok, {{_, status, _}, _, body}} = :httpc.request(:get, {url, headers}, http_options, [body_format: :binary])
IO.inspect(status)
IO.puts(body)

```

**Lua · Lua-cURL**

```lua
-- Requires Lua-cURL; libcurl retains its default TLS verification.
local curl = require('cURL')
local response = {}
local request = curl.easy {
  url = "https://jsonplaceholder.typicode.com/posts?userId=1",
  customrequest = "GET",
  httpheader = {
  },
  writefunction = function(chunk)
    response[#response + 1] = chunk
    return #chunk
  end
}
request:perform()
request:close()
print(table.concat(response))

```

**F# · HttpClient**

```fsharp
open System.Net.Http
open System.Text

use client = new HttpClient()
use request = new HttpRequestMessage(HttpMethod("GET"), "https://jsonplaceholder.typicode.com/posts?userId=1")
use response = client.SendAsync(request).GetAwaiter().GetResult()
printfn "%s" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())

```

**Visual Basic · HttpClient**

```visualbasic
Imports System.Net.Http
Imports System.Text

Module Example
  Sub Main()
    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod("GET"), "https://jsonplaceholder.typicode.com/posts?userId=1")
      Using response = client.SendAsync(request).GetAwaiter().GetResult()
        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())
      End Using
    End Using
  End Sub
End Module

```

**PowerShell · Invoke-RestMethod**

```powershell
$headers = @{
}
$response = Invoke-RestMethod -Method 'GET' -Uri 'https://jsonplaceholder.typicode.com/posts?userId=1' -Headers $headers
$response | ConvertTo-Json -Depth 20

```

**R · httr**

```r
library(httr)

headers <- setNames(c(), c())
response <- VERB("GET", "https://jsonplaceholder.typicode.com/posts?userId=1", add_headers(.headers = headers))
stop_for_status(response)
cat(content(response, as = "text", encoding = "UTF-8"))

```

**Response** — `200`

```json
[
  {
    "id": 1,
    "userId": 1,
    "title": "An example post",
    "body": "Example response content. Live post text can differ."
  }
]
```

---

### Create a post

Send a JSON request body. JSONPlaceholder returns a simulated creation response; a later GET will not retrieve this new post.

**`POST`** `/posts`

**Body**

| Name | Type | Required | Description |

| --- | --- | --- | --- |

| `title` | `string` | ✓ | The post title. |

| `body` | `string` | ✓ | Plain-text content of the post. |

| `userId` | `integer` | ✓ | User associated with the post. |

**Request**

**cURL**

```bash
curl --request POST \
  --url 'https://jsonplaceholder.typicode.com/posts' \
  --header 'Content-Type: application/json' \
  --data '{
  "title": "Hello from Docsy",
  "body": "This request example comes from OpenAPI, not hardcoded UI.",
  "userId": 1
}'
```

**JavaScript · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**TypeScript · fetch**

```typescript
const response = await fetch("https://jsonplaceholder.typicode.com/posts", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Node.js · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Python · requests**

```python
import requests

response = requests.request(
    "POST",
    "https://jsonplaceholder.typicode.com/posts",
    headers={"Content-Type": "application/json"},
    data="{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}".encode("utf-8"),
    timeout=30,
)
response.raise_for_status()
print(response.text)

```

**Go · net/http**

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://jsonplaceholder.typicode.com/posts"

	payload := strings.NewReader("{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

**Java · HttpClient**

```java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://jsonplaceholder.typicode.com/posts"))
    .header("Content-Type", "application/json")
    .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}"))
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**Kotlin · OkHttp**

```kotlin
// Requires OkHttp 4.x.
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody

fun main() {
  val request = Request.Builder()
    .url("https://jsonplaceholder.typicode.com/posts")
    .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()))
    .addHeader("Content-Type", "application/json")
    .build()
  OkHttpClient().newCall(request).execute().use { response ->
    println(response.body?.string())
  }
}

```

**C# · HttpClient**

```csharp
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://jsonplaceholder.typicode.com/posts"),
    Content = new StringContent("{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

**C · libcurl**

```c
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_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}");

CURLcode ret = curl_easy_perform(hnd);
```

**C++ · libcurl**

```cpp
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_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}");

CURLcode ret = curl_easy_perform(hnd);
```

**Rust · reqwest**

```rust
// Cargo: reqwest = "0.12", tokio = { version = "1", features = ["full"] }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::Client::new()
        .request(reqwest::Method::from_bytes("POST".as_bytes())?, "https://jsonplaceholder.typicode.com/posts")
        .header("Content-Type", "application/json")
        .body("{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}")
        .send().await?
        .error_for_status()?;
    println!("{}", response.text().await?);
    Ok(())
}

```

**Swift · URLSession**

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/posts")!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = Data("{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}".utf8)
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))

```

**Objective-C · NSURLSession**

```objectivec
#import <Foundation/Foundation.h>

int main(void) {
  @autoreleasepool {
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://jsonplaceholder.typicode.com/posts"]];
    request.HTTPMethod = @"POST";
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    request.HTTPBody = [@"{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}" dataUsingEncoding:NSUTF8StringEncoding];
    dispatch_semaphore_t done = dispatch_semaphore_create(0);
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      if (error) NSLog(@"%@", error);
      else NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
      dispatch_semaphore_signal(done);
    }] resume];
    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
  }
  return 0;
}

```

**Dart · http**

```dart
// Requires package:http in pubspec.yaml.
import 'package:http/http.dart' as http;

Future<void> main() async {
  final request = http.Request("POST", Uri.parse("https://jsonplaceholder.typicode.com/posts"));
  request.headers.addAll({
    "Content-Type": "application/json",
  });
  request.body = "{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}";
  final response = await request.send();
  print(await response.stream.bytesToString());
}

```

**PHP · cURL**

```php
<?php
$curl = curl_init('https://jsonplaceholder.typicode.com/posts');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => '{
  "title": "Hello from Docsy",
  "body": "This request example comes from OpenAPI, not hardcoded UI.",
  "userId": 1
}',
]);
$response = curl_exec($curl);
if ($response === false) { throw new RuntimeException(curl_error($curl)); }
curl_close($curl);
echo $response;

```

**Ruby · Net::HTTP**

```ruby
require 'uri'
require 'net/http'

url = URI("https://jsonplaceholder.typicode.com/posts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTPGenericRequest.new("POST", true, true, url.request_uri, {"Content-Type" => "application/json"})
request.body = "{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}"
response = http.request(request)
puts response.body

```

**Scala · Java HttpClient**

```scala
import java.net.URI
import java.net.http.{HttpClient, HttpRequest, HttpResponse}

object Example extends App {
  val request = HttpRequest.newBuilder(URI.create("https://jsonplaceholder.typicode.com/posts"))
    .header("Content-Type", "application/json")
    .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}"))
    .build()
  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())
  println(response.body())
}

```

**Elixir · :httpc**

```elixir
:inets.start()
:ssl.start()
url = String.to_charlist("https://jsonplaceholder.typicode.com/posts")
headers = []
http_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]
{: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])
IO.inspect(status)
IO.puts(body)

```

**Lua · Lua-cURL**

```lua
-- Requires Lua-cURL; libcurl retains its default TLS verification.
local curl = require('cURL')
local response = {}
local request = curl.easy {
  url = "https://jsonplaceholder.typicode.com/posts",
  customrequest = "POST",
  httpheader = {
    "Content-Type: application/json",
  },
  postfields = "{\n  \"title\": \"Hello from Docsy\",\n  \"body\": \"This request example comes from OpenAPI, not hardcoded UI.\",\n  \"userId\": 1\n}",
  writefunction = function(chunk)
    response[#response + 1] = chunk
    return #chunk
  end
}
request:perform()
request:close()
print(table.concat(response))

```

**F# · HttpClient**

```fsharp
open System.Net.Http
open System.Text

use client = new HttpClient()
use request = new HttpRequestMessage(HttpMethod("POST"), "https://jsonplaceholder.typicode.com/posts")
request.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)
request.Content.Headers.ContentType <- System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json")
use response = client.SendAsync(request).GetAwaiter().GetResult()
printfn "%s" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())

```

**Visual Basic · HttpClient**

```visualbasic
Imports System.Net.Http
Imports System.Text

Module Example
  Sub Main()
    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod("POST"), "https://jsonplaceholder.typicode.com/posts")
      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)
      request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json")
      Using response = client.SendAsync(request).GetAwaiter().GetResult()
        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())
      End Using
    End Using
  End Sub
End Module

```

**PowerShell · Invoke-RestMethod**

```powershell
$headers = @{
}
$response = Invoke-RestMethod -Method 'POST' -Uri 'https://jsonplaceholder.typicode.com/posts' -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes('{
  "title": "Hello from Docsy",
  "body": "This request example comes from OpenAPI, not hardcoded UI.",
  "userId": 1
}')) -ContentType 'application/json'
$response | ConvertTo-Json -Depth 20

```

**R · httr**

```r
library(httr)

headers <- setNames(c("application/json"), c("Content-Type"))
response <- 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}")))
stop_for_status(response)
cat(content(response, as = "text", encoding = "UTF-8"))

```

**Response** — `201`

```json
{
  "id": 101,
  "title": "Hello from Docsy",
  "body": "This request example comes from OpenAPI, not hardcoded UI.",
  "userId": 1
}
```

---

### Get a post

Fetch one post by its ID. The generated curl command substitutes the path parameter example from this specification.

**`GET`** `/posts/{id}`

**Path parameters**

| Name | Type | Required | Description |

| --- | --- | --- | --- |

| `id` | `integer` | ✓ | Existing post identifier. The request example uses post 1. |

**Request**

**cURL**

```bash
curl --request GET \
  --url 'https://jsonplaceholder.typicode.com/posts/1'
```

**JavaScript · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "GET",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**TypeScript · fetch**

```typescript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "GET",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Node.js · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "GET",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Python · requests**

```python
import requests

response = requests.request(
    "GET",
    "https://jsonplaceholder.typicode.com/posts/1",
    headers={},
    timeout=30,
)
response.raise_for_status()
print(response.text)

```

**Go · net/http**

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://jsonplaceholder.typicode.com/posts/1"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

**Java · HttpClient**

```java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://jsonplaceholder.typicode.com/posts/1"))
    .method("GET", HttpRequest.BodyPublishers.noBody())
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**Kotlin · OkHttp**

```kotlin
// Requires OkHttp 4.x.
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody

fun main() {
  val request = Request.Builder()
    .url("https://jsonplaceholder.typicode.com/posts/1")
    .method("GET", null)
    .build()
  OkHttpClient().newCall(request).execute().use { response ->
    println(response.body?.string())
  }
}

```

**C# · HttpClient**

```csharp
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new Uri("https://jsonplaceholder.typicode.com/posts/1"),
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

**C · libcurl**

```c
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts/1");

CURLcode ret = curl_easy_perform(hnd);
```

**C++ · libcurl**

```cpp
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts/1");

CURLcode ret = curl_easy_perform(hnd);
```

**Rust · reqwest**

```rust
// Cargo: reqwest = "0.12", tokio = { version = "1", features = ["full"] }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::Client::new()
        .request(reqwest::Method::from_bytes("GET".as_bytes())?, "https://jsonplaceholder.typicode.com/posts/1")
        .send().await?
        .error_for_status()?;
    println!("{}", response.text().await?);
    Ok(())
}

```

**Swift · URLSession**

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/posts/1")!)
request.httpMethod = "GET"
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))

```

**Objective-C · NSURLSession**

```objectivec
#import <Foundation/Foundation.h>

int main(void) {
  @autoreleasepool {
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://jsonplaceholder.typicode.com/posts/1"]];
    request.HTTPMethod = @"GET";
    dispatch_semaphore_t done = dispatch_semaphore_create(0);
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      if (error) NSLog(@"%@", error);
      else NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
      dispatch_semaphore_signal(done);
    }] resume];
    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
  }
  return 0;
}

```

**Dart · http**

```dart
// Requires package:http in pubspec.yaml.
import 'package:http/http.dart' as http;

Future<void> main() async {
  final request = http.Request("GET", Uri.parse("https://jsonplaceholder.typicode.com/posts/1"));
  request.headers.addAll({
  });
  final response = await request.send();
  print(await response.stream.bytesToString());
}

```

**PHP · cURL**

```php
<?php
$curl = curl_init('https://jsonplaceholder.typicode.com/posts/1');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [],
]);
$response = curl_exec($curl);
if ($response === false) { throw new RuntimeException(curl_error($curl)); }
curl_close($curl);
echo $response;

```

**Ruby · Net::HTTP**

```ruby
require 'uri'
require 'net/http'

url = URI("https://jsonplaceholder.typicode.com/posts/1")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTPGenericRequest.new("GET", false, true, url.request_uri, {})
response = http.request(request)
puts response.body

```

**Scala · Java HttpClient**

```scala
import java.net.URI
import java.net.http.{HttpClient, HttpRequest, HttpResponse}

object Example extends App {
  val request = HttpRequest.newBuilder(URI.create("https://jsonplaceholder.typicode.com/posts/1"))
    .method("GET", HttpRequest.BodyPublishers.noBody())
    .build()
  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())
  println(response.body())
}

```

**Elixir · :httpc**

```elixir
:inets.start()
:ssl.start()
url = String.to_charlist("https://jsonplaceholder.typicode.com/posts/1")
headers = []
http_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]
{:ok, {{_, status, _}, _, body}} = :httpc.request(:get, {url, headers}, http_options, [body_format: :binary])
IO.inspect(status)
IO.puts(body)

```

**Lua · Lua-cURL**

```lua
-- Requires Lua-cURL; libcurl retains its default TLS verification.
local curl = require('cURL')
local response = {}
local request = curl.easy {
  url = "https://jsonplaceholder.typicode.com/posts/1",
  customrequest = "GET",
  httpheader = {
  },
  writefunction = function(chunk)
    response[#response + 1] = chunk
    return #chunk
  end
}
request:perform()
request:close()
print(table.concat(response))

```

**F# · HttpClient**

```fsharp
open System.Net.Http
open System.Text

use client = new HttpClient()
use request = new HttpRequestMessage(HttpMethod("GET"), "https://jsonplaceholder.typicode.com/posts/1")
use response = client.SendAsync(request).GetAwaiter().GetResult()
printfn "%s" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())

```

**Visual Basic · HttpClient**

```visualbasic
Imports System.Net.Http
Imports System.Text

Module Example
  Sub Main()
    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod("GET"), "https://jsonplaceholder.typicode.com/posts/1")
      Using response = client.SendAsync(request).GetAwaiter().GetResult()
        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())
      End Using
    End Using
  End Sub
End Module

```

**PowerShell · Invoke-RestMethod**

```powershell
$headers = @{
}
$response = Invoke-RestMethod -Method 'GET' -Uri 'https://jsonplaceholder.typicode.com/posts/1' -Headers $headers
$response | ConvertTo-Json -Depth 20

```

**R · httr**

```r
library(httr)

headers <- setNames(c(), c())
response <- VERB("GET", "https://jsonplaceholder.typicode.com/posts/1", add_headers(.headers = headers))
stop_for_status(response)
cat(content(response, as = "text", encoding = "UTF-8"))

```

**Response** — `200`

```json
{
  "id": 1,
  "userId": 1,
  "title": "An example post",
  "body": "Example response content. Live post text can differ."
}
```

---

### Replace a post

Send all writable fields in a JSON body. The replacement is simulated and is not persisted.

**`PUT`** `/posts/{id}`

**Path parameters**

| Name | Type | Required | Description |

| --- | --- | --- | --- |

| `id` | `integer` | ✓ | Existing post identifier. The request example uses post 1. |

**Body**

| Name | Type | Required | Description |

| --- | --- | --- | --- |

| `title` | `string` | ✓ | The post title. |

| `body` | `string` | ✓ | Plain-text content of the post. |

| `userId` | `integer` | ✓ | User associated with the post. |

**Request**

**cURL**

```bash
curl --request PUT \
  --url 'https://jsonplaceholder.typicode.com/posts/1' \
  --header 'Content-Type: application/json' \
  --data '{
  "title": "A replacement post",
  "body": "Replace the complete writable post content.",
  "userId": 1
}'
```

**JavaScript · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**TypeScript · fetch**

```typescript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Node.js · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Python · requests**

```python
import requests

response = requests.request(
    "PUT",
    "https://jsonplaceholder.typicode.com/posts/1",
    headers={"Content-Type": "application/json"},
    data="{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}".encode("utf-8"),
    timeout=30,
)
response.raise_for_status()
print(response.text)

```

**Go · net/http**

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://jsonplaceholder.typicode.com/posts/1"

	payload := strings.NewReader("{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

**Java · HttpClient**

```java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://jsonplaceholder.typicode.com/posts/1"))
    .header("Content-Type", "application/json")
    .method("PUT", HttpRequest.BodyPublishers.ofString("{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}"))
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**Kotlin · OkHttp**

```kotlin
// Requires OkHttp 4.x.
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody

fun main() {
  val request = Request.Builder()
    .url("https://jsonplaceholder.typicode.com/posts/1")
    .method("PUT", "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}".toRequestBody("application/json".toMediaType()))
    .addHeader("Content-Type", "application/json")
    .build()
  OkHttpClient().newCall(request).execute().use { response ->
    println(response.body?.string())
  }
}

```

**C# · HttpClient**

```csharp
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Put,
    RequestUri = new Uri("https://jsonplaceholder.typicode.com/posts/1"),
    Content = new StringContent("{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

**C · libcurl**

```c
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts/1");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}");

CURLcode ret = curl_easy_perform(hnd);
```

**C++ · libcurl**

```cpp
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts/1");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}");

CURLcode ret = curl_easy_perform(hnd);
```

**Rust · reqwest**

```rust
// Cargo: reqwest = "0.12", tokio = { version = "1", features = ["full"] }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::Client::new()
        .request(reqwest::Method::from_bytes("PUT".as_bytes())?, "https://jsonplaceholder.typicode.com/posts/1")
        .header("Content-Type", "application/json")
        .body("{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}")
        .send().await?
        .error_for_status()?;
    println!("{}", response.text().await?);
    Ok(())
}

```

**Swift · URLSession**

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/posts/1")!)
request.httpMethod = "PUT"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = Data("{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}".utf8)
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))

```

**Objective-C · NSURLSession**

```objectivec
#import <Foundation/Foundation.h>

int main(void) {
  @autoreleasepool {
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://jsonplaceholder.typicode.com/posts/1"]];
    request.HTTPMethod = @"PUT";
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    request.HTTPBody = [@"{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}" dataUsingEncoding:NSUTF8StringEncoding];
    dispatch_semaphore_t done = dispatch_semaphore_create(0);
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      if (error) NSLog(@"%@", error);
      else NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
      dispatch_semaphore_signal(done);
    }] resume];
    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
  }
  return 0;
}

```

**Dart · http**

```dart
// Requires package:http in pubspec.yaml.
import 'package:http/http.dart' as http;

Future<void> main() async {
  final request = http.Request("PUT", Uri.parse("https://jsonplaceholder.typicode.com/posts/1"));
  request.headers.addAll({
    "Content-Type": "application/json",
  });
  request.body = "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}";
  final response = await request.send();
  print(await response.stream.bytesToString());
}

```

**PHP · cURL**

```php
<?php
$curl = curl_init('https://jsonplaceholder.typicode.com/posts/1');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => '{
  "title": "A replacement post",
  "body": "Replace the complete writable post content.",
  "userId": 1
}',
]);
$response = curl_exec($curl);
if ($response === false) { throw new RuntimeException(curl_error($curl)); }
curl_close($curl);
echo $response;

```

**Ruby · Net::HTTP**

```ruby
require 'uri'
require 'net/http'

url = URI("https://jsonplaceholder.typicode.com/posts/1")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTPGenericRequest.new("PUT", true, true, url.request_uri, {"Content-Type" => "application/json"})
request.body = "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}"
response = http.request(request)
puts response.body

```

**Scala · Java HttpClient**

```scala
import java.net.URI
import java.net.http.{HttpClient, HttpRequest, HttpResponse}

object Example extends App {
  val request = HttpRequest.newBuilder(URI.create("https://jsonplaceholder.typicode.com/posts/1"))
    .header("Content-Type", "application/json")
    .method("PUT", HttpRequest.BodyPublishers.ofString("{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}"))
    .build()
  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())
  println(response.body())
}

```

**Elixir · :httpc**

```elixir
:inets.start()
:ssl.start()
url = String.to_charlist("https://jsonplaceholder.typicode.com/posts/1")
headers = []
http_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]
{: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])
IO.inspect(status)
IO.puts(body)

```

**Lua · Lua-cURL**

```lua
-- Requires Lua-cURL; libcurl retains its default TLS verification.
local curl = require('cURL')
local response = {}
local request = curl.easy {
  url = "https://jsonplaceholder.typicode.com/posts/1",
  customrequest = "PUT",
  httpheader = {
    "Content-Type: application/json",
  },
  postfields = "{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}",
  writefunction = function(chunk)
    response[#response + 1] = chunk
    return #chunk
  end
}
request:perform()
request:close()
print(table.concat(response))

```

**F# · HttpClient**

```fsharp
open System.Net.Http
open System.Text

use client = new HttpClient()
use request = new HttpRequestMessage(HttpMethod("PUT"), "https://jsonplaceholder.typicode.com/posts/1")
request.Content <- new StringContent("{\n  \"title\": \"A replacement post\",\n  \"body\": \"Replace the complete writable post content.\",\n  \"userId\": 1\n}", Encoding.UTF8)
request.Content.Headers.ContentType <- System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json")
use response = client.SendAsync(request).GetAwaiter().GetResult()
printfn "%s" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())

```

**Visual Basic · HttpClient**

```visualbasic
Imports System.Net.Http
Imports System.Text

Module Example
  Sub Main()
    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod("PUT"), "https://jsonplaceholder.typicode.com/posts/1")
      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)
      request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json")
      Using response = client.SendAsync(request).GetAwaiter().GetResult()
        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())
      End Using
    End Using
  End Sub
End Module

```

**PowerShell · Invoke-RestMethod**

```powershell
$headers = @{
}
$response = Invoke-RestMethod -Method 'PUT' -Uri 'https://jsonplaceholder.typicode.com/posts/1' -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes('{
  "title": "A replacement post",
  "body": "Replace the complete writable post content.",
  "userId": 1
}')) -ContentType 'application/json'
$response | ConvertTo-Json -Depth 20

```

**R · httr**

```r
library(httr)

headers <- setNames(c("application/json"), c("Content-Type"))
response <- 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}")))
stop_for_status(response)
cat(content(response, as = "text", encoding = "UTF-8"))

```

**Response** — `200`

```json
{
  "id": 1,
  "title": "A replacement post",
  "body": "Replace the complete writable post content.",
  "userId": 1
}
```

---

### Update a post title

Send only the fields to change. This request demonstrates a partial JSON body; changes are not persisted.

**`PATCH`** `/posts/{id}`

**Path parameters**

| Name | Type | Required | Description |

| --- | --- | --- | --- |

| `id` | `integer` | ✓ | Existing post identifier. The request example uses post 1. |

**Body**

| Name | Type | Required | Description |

| --- | --- | --- | --- |

| `title` | `string` | ✓ | Replacement title; other post fields remain unchanged. |

**Request**

**cURL**

```bash
curl --request PATCH \
  --url 'https://jsonplaceholder.typicode.com/posts/1' \
  --header 'Content-Type: application/json' \
  --data '{
  "title": "An updated title from Docsy"
}'
```

**JavaScript · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "PATCH",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"An updated title from Docsy\"\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**TypeScript · fetch**

```typescript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "PATCH",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"An updated title from Docsy\"\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Node.js · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "PATCH",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\n  \"title\": \"An updated title from Docsy\"\n}",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Python · requests**

```python
import requests

response = requests.request(
    "PATCH",
    "https://jsonplaceholder.typicode.com/posts/1",
    headers={"Content-Type": "application/json"},
    data="{\n  \"title\": \"An updated title from Docsy\"\n}".encode("utf-8"),
    timeout=30,
)
response.raise_for_status()
print(response.text)

```

**Go · net/http**

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://jsonplaceholder.typicode.com/posts/1"

	payload := strings.NewReader("{\n  \"title\": \"An updated title from Docsy\"\n}")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

**Java · HttpClient**

```java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://jsonplaceholder.typicode.com/posts/1"))
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("{\n  \"title\": \"An updated title from Docsy\"\n}"))
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**Kotlin · OkHttp**

```kotlin
// Requires OkHttp 4.x.
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody

fun main() {
  val request = Request.Builder()
    .url("https://jsonplaceholder.typicode.com/posts/1")
    .method("PATCH", "{\n  \"title\": \"An updated title from Docsy\"\n}".toRequestBody("application/json".toMediaType()))
    .addHeader("Content-Type", "application/json")
    .build()
  OkHttpClient().newCall(request).execute().use { response ->
    println(response.body?.string())
  }
}

```

**C# · HttpClient**

```csharp
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Patch,
    RequestUri = new Uri("https://jsonplaceholder.typicode.com/posts/1"),
    Content = new StringContent("{\n  \"title\": \"An updated title from Docsy\"\n}")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

**C · libcurl**

```c
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts/1");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\n  \"title\": \"An updated title from Docsy\"\n}");

CURLcode ret = curl_easy_perform(hnd);
```

**C++ · libcurl**

```cpp
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts/1");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\n  \"title\": \"An updated title from Docsy\"\n}");

CURLcode ret = curl_easy_perform(hnd);
```

**Rust · reqwest**

```rust
// Cargo: reqwest = "0.12", tokio = { version = "1", features = ["full"] }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::Client::new()
        .request(reqwest::Method::from_bytes("PATCH".as_bytes())?, "https://jsonplaceholder.typicode.com/posts/1")
        .header("Content-Type", "application/json")
        .body("{\n  \"title\": \"An updated title from Docsy\"\n}")
        .send().await?
        .error_for_status()?;
    println!("{}", response.text().await?);
    Ok(())
}

```

**Swift · URLSession**

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/posts/1")!)
request.httpMethod = "PATCH"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = Data("{\n  \"title\": \"An updated title from Docsy\"\n}".utf8)
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))

```

**Objective-C · NSURLSession**

```objectivec
#import <Foundation/Foundation.h>

int main(void) {
  @autoreleasepool {
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://jsonplaceholder.typicode.com/posts/1"]];
    request.HTTPMethod = @"PATCH";
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    request.HTTPBody = [@"{\n  \"title\": \"An updated title from Docsy\"\n}" dataUsingEncoding:NSUTF8StringEncoding];
    dispatch_semaphore_t done = dispatch_semaphore_create(0);
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      if (error) NSLog(@"%@", error);
      else NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
      dispatch_semaphore_signal(done);
    }] resume];
    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
  }
  return 0;
}

```

**Dart · http**

```dart
// Requires package:http in pubspec.yaml.
import 'package:http/http.dart' as http;

Future<void> main() async {
  final request = http.Request("PATCH", Uri.parse("https://jsonplaceholder.typicode.com/posts/1"));
  request.headers.addAll({
    "Content-Type": "application/json",
  });
  request.body = "{\n  \"title\": \"An updated title from Docsy\"\n}";
  final response = await request.send();
  print(await response.stream.bytesToString());
}

```

**PHP · cURL**

```php
<?php
$curl = curl_init('https://jsonplaceholder.typicode.com/posts/1');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => '{
  "title": "An updated title from Docsy"
}',
]);
$response = curl_exec($curl);
if ($response === false) { throw new RuntimeException(curl_error($curl)); }
curl_close($curl);
echo $response;

```

**Ruby · Net::HTTP**

```ruby
require 'uri'
require 'net/http'

url = URI("https://jsonplaceholder.typicode.com/posts/1")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTPGenericRequest.new("PATCH", true, true, url.request_uri, {"Content-Type" => "application/json"})
request.body = "{\n  \"title\": \"An updated title from Docsy\"\n}"
response = http.request(request)
puts response.body

```

**Scala · Java HttpClient**

```scala
import java.net.URI
import java.net.http.{HttpClient, HttpRequest, HttpResponse}

object Example extends App {
  val request = HttpRequest.newBuilder(URI.create("https://jsonplaceholder.typicode.com/posts/1"))
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("{\n  \"title\": \"An updated title from Docsy\"\n}"))
    .build()
  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())
  println(response.body())
}

```

**Elixir · :httpc**

```elixir
:inets.start()
:ssl.start()
url = String.to_charlist("https://jsonplaceholder.typicode.com/posts/1")
headers = []
http_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]
{: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])
IO.inspect(status)
IO.puts(body)

```

**Lua · Lua-cURL**

```lua
-- Requires Lua-cURL; libcurl retains its default TLS verification.
local curl = require('cURL')
local response = {}
local request = curl.easy {
  url = "https://jsonplaceholder.typicode.com/posts/1",
  customrequest = "PATCH",
  httpheader = {
    "Content-Type: application/json",
  },
  postfields = "{\n  \"title\": \"An updated title from Docsy\"\n}",
  writefunction = function(chunk)
    response[#response + 1] = chunk
    return #chunk
  end
}
request:perform()
request:close()
print(table.concat(response))

```

**F# · HttpClient**

```fsharp
open System.Net.Http
open System.Text

use client = new HttpClient()
use request = new HttpRequestMessage(HttpMethod("PATCH"), "https://jsonplaceholder.typicode.com/posts/1")
request.Content <- new StringContent("{\n  \"title\": \"An updated title from Docsy\"\n}", Encoding.UTF8)
request.Content.Headers.ContentType <- System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json")
use response = client.SendAsync(request).GetAwaiter().GetResult()
printfn "%s" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())

```

**Visual Basic · HttpClient**

```visualbasic
Imports System.Net.Http
Imports System.Text

Module Example
  Sub Main()
    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod("PATCH"), "https://jsonplaceholder.typicode.com/posts/1")
      request.Content = New StringContent("{" & ChrW(10) & "  ""title"": ""An updated title from Docsy""" & ChrW(10) & "}", Encoding.UTF8)
      request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json")
      Using response = client.SendAsync(request).GetAwaiter().GetResult()
        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())
      End Using
    End Using
  End Sub
End Module

```

**PowerShell · Invoke-RestMethod**

```powershell
$headers = @{
}
$response = Invoke-RestMethod -Method 'PATCH' -Uri 'https://jsonplaceholder.typicode.com/posts/1' -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes('{
  "title": "An updated title from Docsy"
}')) -ContentType 'application/json'
$response | ConvertTo-Json -Depth 20

```

**R · httr**

```r
library(httr)

headers <- setNames(c("application/json"), c("Content-Type"))
response <- VERB("PATCH", "https://jsonplaceholder.typicode.com/posts/1", add_headers(.headers = headers), body = charToRaw(enc2utf8("{\n  \"title\": \"An updated title from Docsy\"\n}")))
stop_for_status(response)
cat(content(response, as = "text", encoding = "UTF-8"))

```

**Response** — `200`

```json
{
  "id": 1,
  "userId": 1,
  "title": "An updated title from Docsy",
  "body": "Original post body, unchanged by this PATCH."
}
```

---

### Delete a post

Simulate deletion of a post. JSONPlaceholder leaves the original post available; this request does not delete persistent data.

**`DELETE`** `/posts/{id}`

**Path parameters**

| Name | Type | Required | Description |

| --- | --- | --- | --- |

| `id` | `integer` | ✓ | Existing post identifier. The request example uses post 1. |

**Request**

**cURL**

```bash
curl --request DELETE \
  --url 'https://jsonplaceholder.typicode.com/posts/1'
```

**JavaScript · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "DELETE",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**TypeScript · fetch**

```typescript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "DELETE",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Node.js · fetch**

```javascript
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1", {
  method: "DELETE",
  headers: {},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.text());

```

**Python · requests**

```python
import requests

response = requests.request(
    "DELETE",
    "https://jsonplaceholder.typicode.com/posts/1",
    headers={},
    timeout=30,
)
response.raise_for_status()
print(response.text)

```

**Go · net/http**

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://jsonplaceholder.typicode.com/posts/1"

	req, _ := http.NewRequest("DELETE", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

**Java · HttpClient**

```java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://jsonplaceholder.typicode.com/posts/1"))
    .method("DELETE", HttpRequest.BodyPublishers.noBody())
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**Kotlin · OkHttp**

```kotlin
// Requires OkHttp 4.x.
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody

fun main() {
  val request = Request.Builder()
    .url("https://jsonplaceholder.typicode.com/posts/1")
    .method("DELETE", null)
    .build()
  OkHttpClient().newCall(request).execute().use { response ->
    println(response.body?.string())
  }
}

```

**C# · HttpClient**

```csharp
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Delete,
    RequestUri = new Uri("https://jsonplaceholder.typicode.com/posts/1"),
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

**C · libcurl**

```c
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts/1");

CURLcode ret = curl_easy_perform(hnd);
```

**C++ · libcurl**

```cpp
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://jsonplaceholder.typicode.com/posts/1");

CURLcode ret = curl_easy_perform(hnd);
```

**Rust · reqwest**

```rust
// Cargo: reqwest = "0.12", tokio = { version = "1", features = ["full"] }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::Client::new()
        .request(reqwest::Method::from_bytes("DELETE".as_bytes())?, "https://jsonplaceholder.typicode.com/posts/1")
        .send().await?
        .error_for_status()?;
    println!("{}", response.text().await?);
    Ok(())
}

```

**Swift · URLSession**

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/posts/1")!)
request.httpMethod = "DELETE"
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))

```

**Objective-C · NSURLSession**

```objectivec
#import <Foundation/Foundation.h>

int main(void) {
  @autoreleasepool {
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://jsonplaceholder.typicode.com/posts/1"]];
    request.HTTPMethod = @"DELETE";
    dispatch_semaphore_t done = dispatch_semaphore_create(0);
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      if (error) NSLog(@"%@", error);
      else NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
      dispatch_semaphore_signal(done);
    }] resume];
    dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
  }
  return 0;
}

```

**Dart · http**

```dart
// Requires package:http in pubspec.yaml.
import 'package:http/http.dart' as http;

Future<void> main() async {
  final request = http.Request("DELETE", Uri.parse("https://jsonplaceholder.typicode.com/posts/1"));
  request.headers.addAll({
  });
  final response = await request.send();
  print(await response.stream.bytesToString());
}

```

**PHP · cURL**

```php
<?php
$curl = curl_init('https://jsonplaceholder.typicode.com/posts/1');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [],
]);
$response = curl_exec($curl);
if ($response === false) { throw new RuntimeException(curl_error($curl)); }
curl_close($curl);
echo $response;

```

**Ruby · Net::HTTP**

```ruby
require 'uri'
require 'net/http'

url = URI("https://jsonplaceholder.typicode.com/posts/1")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTPGenericRequest.new("DELETE", false, true, url.request_uri, {})
response = http.request(request)
puts response.body

```

**Scala · Java HttpClient**

```scala
import java.net.URI
import java.net.http.{HttpClient, HttpRequest, HttpResponse}

object Example extends App {
  val request = HttpRequest.newBuilder(URI.create("https://jsonplaceholder.typicode.com/posts/1"))
    .method("DELETE", HttpRequest.BodyPublishers.noBody())
    .build()
  val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())
  println(response.body())
}

```

**Elixir · :httpc**

```elixir
:inets.start()
:ssl.start()
url = String.to_charlist("https://jsonplaceholder.typicode.com/posts/1")
headers = []
http_options = [ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]]]
{:ok, {{_, status, _}, _, body}} = :httpc.request(:delete, {url, headers}, http_options, [body_format: :binary])
IO.inspect(status)
IO.puts(body)

```

**Lua · Lua-cURL**

```lua
-- Requires Lua-cURL; libcurl retains its default TLS verification.
local curl = require('cURL')
local response = {}
local request = curl.easy {
  url = "https://jsonplaceholder.typicode.com/posts/1",
  customrequest = "DELETE",
  httpheader = {
  },
  writefunction = function(chunk)
    response[#response + 1] = chunk
    return #chunk
  end
}
request:perform()
request:close()
print(table.concat(response))

```

**F# · HttpClient**

```fsharp
open System.Net.Http
open System.Text

use client = new HttpClient()
use request = new HttpRequestMessage(HttpMethod("DELETE"), "https://jsonplaceholder.typicode.com/posts/1")
use response = client.SendAsync(request).GetAwaiter().GetResult()
printfn "%s" (response.Content.ReadAsStringAsync().GetAwaiter().GetResult())

```

**Visual Basic · HttpClient**

```visualbasic
Imports System.Net.Http
Imports System.Text

Module Example
  Sub Main()
    Using client As New HttpClient(), request As New HttpRequestMessage(New HttpMethod("DELETE"), "https://jsonplaceholder.typicode.com/posts/1")
      Using response = client.SendAsync(request).GetAwaiter().GetResult()
        Console.WriteLine(response.Content.ReadAsStringAsync().GetAwaiter().GetResult())
      End Using
    End Using
  End Sub
End Module

```

**PowerShell · Invoke-RestMethod**

```powershell
$headers = @{
}
$response = Invoke-RestMethod -Method 'DELETE' -Uri 'https://jsonplaceholder.typicode.com/posts/1' -Headers $headers
$response | ConvertTo-Json -Depth 20

```

**R · httr**

```r
library(httr)

headers <- setNames(c(), c())
response <- VERB("DELETE", "https://jsonplaceholder.typicode.com/posts/1", add_headers(.headers = headers))
stop_for_status(response)
cat(content(response, as = "text", encoding = "UTF-8"))

```

**Response** — `200`

```json
{}
```
