cURL JavaScript TypeScript Python C# Java Go
curl - X POST 'https://api.testingapis.com/api/Orders' \
- H 'Content-Type: application/json' \
- H 'X-TestingApis-Key: YOUR_API_KEY' \
- d '{"userId": 104, "items": [{"productId": 2, "title": "Smartwatch Series 6", "quantity": 1, "price": 199.99}], "shippingAddress": {"street": "1 Main St", "city": "Pune", "state": "MH", "zip": "411001", "country": "IN"}}' const res = await fetch("https://api.testingapis.com/api/Orders", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-TestingApis-Key": "YOUR_API_KEY",
},
body: "{\"userId\": 104, \"items\": [{\"productId\": 2, \"title\": \"Smartwatch Series 6\", \"quantity\": 1, \"price\": 199.99}], \"shippingAddress\": {\"street\": \"1 Main St\", \"city\": \"Pune\", \"state\": \"MH\", \"zip\": \"411001\", \"country\": \"IN\"}}",
});
console.log(res.status, await res.text());// The shape of the example response in the docs.
type ApiResponse = {
message: string;
data: {
id: number;
userId: number;
items: {
productId: number;
title: string;
quantity: number;
price: number;
}[];
total: number;
status: string;
shippingAddress: {
street: string;
city: string;
state: string;
zip: string;
country: string;
};
orderedAt: string;
deliveredAt: null;
};
};
const res = await fetch("https://api.testingapis.com/api/Orders", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-TestingApis-Key": "YOUR_API_KEY",
},
body: "{\"userId\": 104, \"items\": [{\"productId\": 2, \"title\": \"Smartwatch Series 6\", \"quantity\": 1, \"price\": 199.99}], \"shippingAddress\": {\"street\": \"1 Main St\", \"city\": \"Pune\", \"state\": \"MH\", \"zip\": \"411001\", \"country\": \"IN\"}}",
});
const body = (await res.json()) as ApiResponse;
console.log(res.status, body);import requests
res = requests.post(
"https://api.testingapis.com/api/Orders",
headers={
"Content-Type": "application/json",
"X-TestingApis-Key": "YOUR_API_KEY",
},
data="{\"userId\": 104, \"items\": [{\"productId\": 2, \"title\": \"Smartwatch Series 6\", \"quantity\": 1, \"price\": 199.99}], \"shippingAddress\": {\"street\": \"1 Main St\", \"city\": \"Pune\", \"state\": \"MH\", \"zip\": \"411001\", \"country\": \"IN\"}}",
)
print(res.status_code, res.text)using System.Net.Http.Headers;
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://api.testingapis.com/api/Orders");
request.Headers.TryAddWithoutValidation("X-TestingApis-Key", "YOUR_API_KEY");
request.Content = new StringContent("{\"userId\": 104, \"items\": [{\"productId\": 2, \"title\": \"Smartwatch Series 6\", \"quantity\": 1, \"price\": 199.99}], \"shippingAddress\": {\"street\": \"1 Main St\", \"city\": \"Pune\", \"state\": \"MH\", \"zip\": \"411001\", \"country\": \"IN\"}}");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
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/Orders"))
.header("X-TestingApis-Key", "YOUR_API_KEY")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\"userId\": 104, \"items\": [{\"productId\": 2, \"title\": \"Smartwatch Series 6\", \"quantity\": 1, \"price\": 199.99}], \"shippingAddress\": {\"street\": \"1 Main St\", \"city\": \"Pune\", \"state\": \"MH\", \"zip\": \"411001\", \"country\": \"IN\"}}"))
.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("{\"userId\": 104, \"items\": [{\"productId\": 2, \"title\": \"Smartwatch Series 6\", \"quantity\": 1, \"price\": 199.99}], \"shippingAddress\": {\"street\": \"1 Main St\", \"city\": \"Pune\", \"state\": \"MH\", \"zip\": \"411001\", \"country\": \"IN\"}}")
req, err := http.NewRequest("POST", "https://api.testingapis.com/api/Orders", body)
if err != nil {
panic(err)
}
req.Header.Set("X-TestingApis-Key", "YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
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))
}