Authenticate with an API key in the api_key cookie
GET
https://api.testingapis.com/api/auth/api-key/cookieHeader: Cookie: api_key=apibee-key-123.
API key in cookie api_key=apibee-key-123
Responses
- 200
- Authenticated.
- 401
- No key sent, or the key is wrong.
Example
Request
curl -X GET "https://api.testingapis.com/api/auth/api-key/cookie" \
-H "Cookie: api_key=apibee-key-123"Response200 OK
{"authenticated": true, "scheme": "api-key", "location": "api_key cookie"}Code examples
JavaScript (fetch)
// Browsers don't let fetch set a Cookie header; this works in Node.js 18 and later.
const response = await fetch("https://api.testingapis.com/api/auth/api-key/cookie", {
headers: {
"Cookie": "api_key=apibee-key-123",
},
});
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"GET",
"https://api.testingapis.com/api/auth/api-key/cookie",
headers={
"Cookie": "api_key=apibee-key-123",
},
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/auth/api-key/cookie"))
.header("Cookie", "api_key=apibee-key-123")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}