---
title: Esempi di richieste e risposte
description: Scopri come documentare le API con i componenti RequestExample e ResponseExample usando un flusso pratico per i ticket di supporto Acme.
api: GET /tickets/{ticket_id}
---

> **For AI agents:** the complete documentation index is at [llms.txt](/docs/llms.txt). Append `.md` to any page URL for its markdown version.

Usa `RequestExample` e `ResponseExample` per mostrare l'utilizzo reale delle API insieme alla documentazione degli endpoint. I componenti supportano più linguaggi, stati della risposta e spiegazioni inline.

## Esempio: recuperare un ticket di supporto

Questo esempio documenta un semplice endpoint `GET /tickets/{ticket_id}` per l'API di supporto Acme.

### Richiesta

Usa i campi dei parametri per descrivere ciò che l'endpoint si aspetta. L'esempio di codice si trova nella barra laterale destra.

<ParamField path="ticket_id" type="string" required>
  Identificatore univoco del ticket restituito al momento della creazione del ticket.
</ParamField>

<RequestExample>
```bash cURL
curl -X GET https://api.acme.com/v1/tickets/tkt_9S8L2 \
  -H "Authorization: Bearer $ACME_TOKEN"
```

```python Python
import requests

response = requests.get(
    "https://api.acme.com/v1/tickets/tkt_9S8L2",
    headers={"Authorization": f"Bearer {ACME_TOKEN}"}
)

ticket = response.json()
print(ticket["id"])
```

```javascript JavaScript
const response = await fetch("https://api.acme.com/v1/tickets/tkt_9S8L2", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.ACME_TOKEN}`,
  }
});

const ticket = await response.json();
console.log(ticket.id);
```

```go Go
package main

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

func main() {
  req, _ := http.NewRequest("GET", "https://api.acme.com/v1/tickets/tkt_9S8L2", nil)
  req.Header.Set("Authorization", "Bearer ACME_TOKEN")

  resp, _ := (&http.Client{}).Do(req)
  defer resp.Body.Close()

  body, _ := io.ReadAll(resp.Body)
  fmt.Println(string(body))
}
```

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

uri = URI("https://api.acme.com/v1/tickets/tkt_9S8L2")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer ACME_TOKEN"

response = http.request(request)
puts JSON.parse(response.body)
```

```csharp C#
using System.Net.Http;

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer ACME_TOKEN");

var response = await client.GetAsync("https://api.acme.com/v1/tickets/tkt_9S8L2");
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
```

```java Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.acme.com/v1/tickets/tkt_9S8L2"))
    .header("Authorization", "Bearer ACME_TOKEN")
    .GET()
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

```rust Rust
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = reqwest::Client::new();

    let response = client
        .get("https://api.acme.com/v1/tickets/tkt_9S8L2")
        .header("Authorization", "Bearer ACME_TOKEN")
        .send()
        .await?;

    let body = response.text().await?;
    println!("{}", body);

    Ok(())
}
```

```php PHP
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.acme.com/v1/tickets/tkt_9S8L2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ACME_TOKEN']);

$response = curl_exec($ch); curl_close($ch);

echo $response;
```
</RequestExample>

### Risposta

Usa i campi della risposta per documentare gli attributi più importanti restituiti dall'API.

<ResponseField name="id" type="string" required>
  Identificatore univoco del ticket.
</ResponseField>

<ResponseField name="status" type="string">
  Stato attuale del ticket (`open`, `pending` o `resolved`).
</ResponseField>

<ResponseField name="created_at" type="string">
  Timestamp ISO 8601 della creazione del ticket.
</ResponseField>

<ResponseExample>
```json 200: OK
{
  "id": "tkt_9S8L2",
  "customer_id": "cus_2X9W8",
  "subject": "Export stuck on step 3",
  "priority": "high",
  "status": "open",
  "created_at": "2026-02-04T16:12:00Z"
}
```

```json 404: Not found
{
  "code": "not_found",
  "message": "ticket_id does not exist"
}
```
</ResponseExample>

## Suggerimenti

- Includi almeno una risposta di successo e una risposta di errore.
- Usa identificatori e timestamp realistici per rendere concreti gli esempi.
- Mantieni i payload essenziali, così i lettori possono esaminarli rapidamente.

## Pagine correlate

<Columns cols={2}>
  <Card title="API Playground" icon="flask-vial" href="/it/api-reference/playground">
    Abilita i test interattivi delle API nelle pagine degli endpoint
  </Card>
  <Card title="OpenAPI Example" icon="plug" href="/it/api-reference/openapi-example">
    Visualizza una pagina di endpoint generata automaticamente
  </Card>
</Columns>

<Columns cols={2}>
  <Card title="Examples Component" icon="code" href="/it/components/examples">
    Scopri le proprietà del componente e le regole di formattazione
  </Card>
  <Card title="Fields Component" icon="list-check" href="/it/components/fields">
    Documenta gli schemi delle richieste e delle risposte
  </Card>
</Columns>

---

📦 **OpenAPI specs:** Every OpenAPI specification referenced by this documentation is available as a single download — https://jamdesk-docs.jamdesk.app/api-specs.zip