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

Redirects to /api/echo with the chosen redirect status

GETPOSTPUTPATCHDELETEHEADhttps://api.testingapis.com/api/redirect/status/{code}

Redirects to /api/echo with the chosen redirect status.

Accepts GET, POST, PUT, PATCH, DELETE and HEAD. Use it to check client behaviour: after a POST, a 303 should be followed with GET (body dropped), while 307 and 308 must repeat the same method and body. /api/echo shows what arrived.

Parameters 1

NameTypeDescription
coderequiredpath · integer (int32)Redirect status: 301, 302, 303, 307 or 308.

Responses

200
OK
301
Moved Permanently.
302
Found.
303
See Other.
307
Temporary Redirect (method and body kept).
308
Permanent Redirect (method and body kept).
400
Unsupported code.

Example

Request
curl -X GET "https://api.testingapis.com/api/redirect/status/302"
Run in Studio
Response302 Found
Location: /api/echo

{
  "status": 302,
  "statusText": "Found",
  "location": "/api/echo",
  "remaining": null,
  "keepsMethod": false
}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/redirect/status/302");
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "GET",
    "https://api.testingapis.com/api/redirect/status/302",
    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/redirect/status/302"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

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