Generate a random string
GET
https://api.testingapis.com/api/utils/random/stringParameters 3
| Name | Type | Description |
|---|---|---|
length | query · integer (int32) | Length, 1–1000, default 16. Default: 16. |
charset | query · string | alphanumeric (default), alpha, numeric, hex or symbols. Case-insensitive. Default: "alphanumeric". |
seed | query · integer (int32) | Optional seed for repeatable output. |
Responses
- 200
- Success.
- 400
- length is out of range or the charset is unknown.
Example
Request
curl -X GET "https://api.testingapis.com/api/utils/random/string?length=12"Response200 OK
{"value": "xbSPTfUubaO3", "length": 12, "charset": "alphanumeric", "seed": null}Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/utils/random/string?length=12");
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"GET",
"https://api.testingapis.com/api/utils/random/string?length=12",
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/utils/random/string?length=12"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}