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

Reads a plain-text body and counts its bytes, characters, lines and words

POSThttps://api.testingapis.com/api/bodies/text

Up to 1MB is analysed; larger bodies are counted and flagged with truncated.

Request body

Optional. text/plain. Plain text; counts characters, lines and words.

Example body
Hello
world

Responses

200
Text statistics and the text itself.
400
Body is not valid UTF-8.
415
Content-Type is not text/plain.

Example

Request
curl -X POST "https://api.testingapis.com/api/bodies/text" \
  -H "Content-Type: text/plain" \
  -d 'Hello
world'
Run in Studio
Response200 OK
{
  "contentType": "text/plain",
  "bytes": 11,
  "characters": 11,
  "lines": 2,
  "words": 2,
  "truncated": false,
  "text": "Hello\nworld"
}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/bodies/text", {
  method: "POST",
  headers: {
    "Content-Type": "text/plain",
  },
  body: "Hello\nworld",
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "POST",
    "https://api.testingapis.com/api/bodies/text",
    headers={
        "Content-Type": "text/plain",
    },
    data="Hello\nworld".encode("utf-8"),
    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/bodies/text"))
            .header("Content-Type", "text/plain")
            .method("POST", HttpRequest.BodyPublishers.ofString("Hello\nworld"))
            .build();

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