How to Make an API Request
All requests should be made to https://api2.archery-records.net
To make a REST request to an API, you typically use an HTTP client to send a request using the relevant HTTP verb/method (eg GET, POST, PUT, DELETE) to an endpoint. Here’s a breakdown of how to do it in different ways:
1. Using curl
(Command Line)
curl -X GET "https://api2.archery-records.net/api
/<resource>" \
-H "Authorization: YOUR_API_KEY" \
-H "Accept: application/json"
-
-X GET
: HTTP method (use POST, PUT, DELETE, etc. as needed) -
-H
: HTTP headers -
Add
-d '{"key":"value"}'
for data (usually with POST/PUT)
2. Using Python (requests
library)
Example:
import requests
url = "https://api2.archery-records.net/api/<resource>"
headers = {
"Authorization": "YOUR_API_KEY",
"Accept": "application/json"
}
response = requests.get(url, headers=headers)
print(response.status_code)
print(response.json()) # or response.text
For POST with data:
data = {"name": "Alice", "email": "alice@example.com"}
response = requests.post(url, json=data, headers=headers)
3. Using JavaScript (Fetch API - Browser or Node.js)
fetch("https://api2.archery-records.net/api/<resource>", {
method: "GET",
headers: {
"Authorization": "YOUR_API_KEY",
"Accept": "application/json"
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
For POST:
fetch("https://api2.archery-records.net/api/<resource>", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Basic YOUR_API_KEY"
},
body: JSON.stringify({ name: "Alice", email: "alice@example.com" })
})
Common Elements of a REST Request
-
Method: POST (Create), GET (Read), PUT (Update), DELETE (aka CRUD)
-
URL: Endpoint of the API
-
Headers: Often includes
Authorization
,Content-Type
, etc. -
Body: JSON data sent with POST/PUT
Written with the assistance of ChatGPT