Tutorials Overview
Learn to use our API through practical examples and step-by-step guides. This tutorial section walks you through basic requests to advanced patterns.
Your First API Call
1. Setup CLI Tool
npm install my-api-tool
2. Fetch User Data
my-api users
[ {"id":1,"name":"John Doe"}, {"id":2,"name":"Jane Smith"} ]
Authentication Tutorial
Using Bearer Tokens
JavaScript
fetch('https://api.example.com/api/v1/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'user@example.com',
password: 'yourpassword'
})
})
cURL
curl -X POST https://api.example.com/api/v1/auth \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"yourpassword"}'
Response Format
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.xxxxx",
"expires_in": 3600
}
Working with Endpoints
GET /api/v1/posts?author=1
Fetch posts filtered by author ID
Query Parameters
- author - Required
- limit - Optional (default: 10)
- page - Optional (default: 1)
POST /api/v1/comments
Create a new comment with authentication
fetch('https://api.example.com/api/v1/comments', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: "Great article!",
post_id: 123
})
})
Advanced Patterns
Pagination Implementation
Use the following pattern to handle paginated data:
Step 1: Fetch first page
GET /api/v1/posts?limit=20&page=1
Step 2: Fetch next page
GET /api/v1/posts?limit=20&page=2
Step 3: Check for more pages
The response header includes:
'Link: <https://api.example.com/api/v1/posts?limit=20&page=3>'
Filtering Data
Use query parameters for filtering:
/api/v1/posts?status=published
Show published posts
/api/v1/posts?tag=technology
Filter by tag
/api/v1/posts?search=web dev
Search in content