{"schemaVersion":1,"title":"Comments · OpenAPI sample","url":"https://appgram.github.io/docsy/versions/current/fr/api/comments","markdownUrl":"https://appgram.github.io/docsy/format-md/versions/current/fr/api/comments","jsonUrl":"https://appgram.github.io/docsy/agent/pages/versions/current/fr/api/comments.json","version":"current","locale":"fr","markdown":"# Comments · OpenAPI sample\n\nA public GET request with an optional postId filter. The query value, curl command, and response example come from the OpenAPI source.\n\n> Source: https://appgram.github.io/docsy/versions/current/fr/api/comments  \n> Endpoints: 1  \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 comments for a post\n\nFilter comments using a query parameter. Omit `postId` to list all comments. No API key is needed.\n\n**`GET`** `/comments`\n\n**Query parameters**\n\n| Name | Type | Required | Description |\n\n| --- | --- | --- | --- |\n\n| `postId` | `integer` |  | Return only comments belonging to this post. |\n\n**Request**\n\n**cURL**\n\n```bash\ncurl --request GET \\\n  --url 'https://jsonplaceholder.typicode.com/comments?postId=1'\n```\n\n**JavaScript · fetch**\n\n```javascript\nconst response = await fetch(\"https://jsonplaceholder.typicode.com/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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/comments?postId=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    \"postId\": 1,\n    \"name\": \"Example comment\",\n    \"email\": \"reader@example.com\",\n    \"body\": \"Example response content. Live comment text can differ.\"\n  }\n]\n```\n"}