cURL JavaScript TypeScript Python C# Java Go
curl - X POST 'https://api.testingapis.com/api/bodies/form' \
- H 'Content-Type: application/x-www-form-urlencoded' \
- H 'X-TestingApis-Key: YOUR_API_KEY' \
- - data - urlencode 'name=Ada' \
- - data - urlencode 'role=admin' const res = await fetch("https://api.testingapis.com/api/bodies/form", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-TestingApis-Key": "YOUR_API_KEY",
},
body: new URLSearchParams({
"name": "Ada",
"role": "admin",
}),
});
console.log(res.status, await res.text());// The shape of the example response in the docs.
type ApiResponse = {
contentType: string;
encoding: string;
fields: {
name: string;
role: string;
};
files: unknown[];
};
const res = await fetch("https://api.testingapis.com/api/bodies/form", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-TestingApis-Key": "YOUR_API_KEY",
},
body: new URLSearchParams({
"name": "Ada",
"role": "admin",
}),
});
const body = (await res.json()) as ApiResponse;
console.log(res.status, body);import requests
res = requests.post(
"https://api.testingapis.com/api/bodies/form",
headers={
"Content-Type": "application/x-www-form-urlencoded",
"X-TestingApis-Key": "YOUR_API_KEY",
},
data={"name": "Ada", "role": "admin"},
)
print(res.status_code, res.text)using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://api.testingapis.com/api/bodies/form");
request.Headers.TryAddWithoutValidation("X-TestingApis-Key", "YOUR_API_KEY");
request.Content = new FormUrlEncodedContent(
[
new("name", "Ada"),
new("role", "admin"),
]);
using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");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.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.testingapis.com/api/bodies/form"))
.header("X-TestingApis-Key", "YOUR_API_KEY")
.header("Content-Type", "application/x-www-form-urlencoded")
.method("POST", HttpRequest.BodyPublishers.ofString("name=Ada&role=admin"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
body := strings.NewReader("name=Ada&role=admin")
req, err := http.NewRequest("POST", "https://api.testingapis.com/api/bodies/form", body)
if err != nil {
panic(err)
}
req.Header.Set("X-TestingApis-Key", "YOUR_API_KEY")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(res.StatusCode, string(data))
}