Test and explore REST APIs with ease
No response yet
Configure your request and click send to see the response here
/testapi/json
/testapi/json2
/testapi/text
/testapi/xml
/testapi/<data-type>/<status-code>
/testapi/QP?user=santosh&website=pynfinity
/testapi/post
Supports JSON, Form Data, and URL Encoded payloads.
{ "key": "value" }
/testapi/3b4c5d6e-7f8a-9b0c-1d2e-3f4a5b6c7d8e
/testapi/7c8d9e0f-1a2b-3c4d-5e6f-7a8b9c0d1e2f/202
Use "id" as identifier | target-structure is
/testapi/json2
i.wish.i.know.pynfinity.b4
iLoveUsingPynfinity
USERNAME:admin
PASSWORD:pynfinity
Generate token using
/testapi/token
Token Expires in 60 minutes
Fetch a mocked JSON payload to test your UI integration.
Test sending standard form submissions dynamically.
Send a full object update to a unique identifier.
Imagine you are sitting at a restaurant. You want a burger. You don't go to the kitchen to cook it yourself. Instead, you tell the waiter your order, the waiter takes it to the kitchen, and brings your burger back to your table.
A REST API (Representational State Transfer) is exactly like that waiter. It's a popular, lightweight way for two computer programs to talk to each other over the internet. Your program (the customer) sends a request to a server (the kitchen), and the server sends back the data you asked for (the burger).
When you talk to a REST API, you use standard "HTTP Methods" (verbs) to explain what you want to achieve:
READ: "Give me information." (e.g., Get my user profile or get the weather).
CREATE: "Here is some new info, save it." (e.g., Create a new account).
UPDATE: "Change this existing info." (e.g., Update my email address).
REMOVE: "Delete this info." (e.g., Delete my old photo).
While SOAP uses a strict language called XML, REST almost always uses JSON (JavaScript Object Notation). It looks exactly like a Python Dictionary! It's super easy for humans to read and computers to process.
{
"username": "santoshtvk",
"score": 9000,
"is_active": true
}
Python has an amazing, magical library called requests that makes talking to REST APIs incredibly simple. By far, it is the most popular library you will ever use in Python!
Step 1: Install it
pip install requests
Step 2: Basic Example (GET Request)
Let's try to "GET" some data from an API (like checking the weather).
import requests # 1. Ask the server for data response = requests.get("https://pynfinity.com/welcome/testapi/json") # 2. Check if the server says '200 OK' (meaning Success!) if response.status_code == 200: # 3. Convert the JSON answer into a Python Dictionary data = response.json() print(f"First content id is: {data[0]['id']}")
Step 3: Advanced Example (POST Request with Security Base)
When creating a new user or buying an item, we use POST. We also need to send SECURE headers, like an API Key, to prove who we are!
import requests url = "https://api.example.com/v1/posts" # The data we want to send (like filling out a form) payload = { "title": "Learning REST APIs", "body": "This is so much easier than I thought!" } # Secret IDs/Passes go in the Header headers = { "Authorization": "Bearer SUPER_SECRET_TOKEN_123", "Content-Type": "application/json" } # We use requests.post() instead of .get() response = requests.post(url, json=payload, headers=headers) if response.status_code == 201: # 201 means "Created" print("Successfully created the post!")
Practice making GET, POST, and PUT requests yourself using the Playground above! ๐ป