New in 2.4: Test runs you can trust See what's new →

Return the same user in the format chosen by the Accept header

GEThttps://api.testingapis.com/api/formats/negotiate

Return the same user in the format chosen by the Accept header.

Supported media types: application/json, application/xml, text/xml, text/html, text/plain and text/csv. Types are tried in descending q-value order and q=0 excludes a type. */* and application/* map to JSON, text/* maps to plain text, and a missing Accept header yields JSON. Every response carries Vary: Accept. Every format carries the same fields as the JSON.

Responses

200
The user in the negotiated format.
406
No acceptable media type; the body lists the supported ones.

Example

Request
curl -X GET "https://api.testingapis.com/api/formats/negotiate" \
  -H "Accept: text/csv"
Run in Studio
Response200 OK
Content-Type: text/csv; charset=utf-8
Vary: Accept

id,name,email,roles,active,score,manager
1,Alice Johnson,alice@example.com,admin;editor,true,98.5,

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/formats/negotiate", {
  headers: {
    "Accept": "text/csv",
  },
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "GET",
    "https://api.testingapis.com/api/formats/negotiate",
    headers={
        "Accept": "text/csv",
    },
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/formats/negotiate"))
            .header("Accept", "text/csv")
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

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