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

Stream newline-delimited JSON, one object per line

GEThttps://api.testingapis.com/api/stream/ndjson/{n}

Content type is application/x-ndjson. Swagger UI shows the result only after the stream ends; to watch lines arrive use curl -N "https://api.testingapis.com/api/stream/ndjson/20?intervalMs=200".

Parameters 2

NameTypeDescription
nrequiredpath · integer (int32)Number of lines (1-1000; out-of-range values are clamped).
intervalMsquery · integer (int32)Delay between lines in milliseconds (0-5000, default 0). Default: 0.

Responses

200
NDJSON lines.

Example

Request
curl -X GET "https://api.testingapis.com/api/stream/ndjson/3"
Run in Studio
Response200 OK
Content-Type: application/x-ndjson
Cache-Control: no-cache

{"id":1,"name":"Alpha-001","value":3.14,"even":false}
{"id":2,"name":"Bravo-002","value":6.28,"even":true}
{"id":3,"name":"Charlie-003","value":9.42,"even":false}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/stream/ndjson/3");
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "GET",
    "https://api.testingapis.com/api/stream/ndjson/3",
    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/stream/ndjson/3"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

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