API Specifications
API Specifications
Overview
This document provides links and information about the Learnille platform’s API specifications.
API Documentation
Swagger/OpenAPI Specifications
The Learnille API is documented using OpenAPI 3.0 specification and is available through interactive Swagger UI documentation.
Production API Documentation
- URL: https://api.learnille.com/docs
- Swagger UI: Interactive API explorer
- OpenAPI JSON: https://api.learnille.com/docs/openapi.json
Development API Documentation
- URL: https://api-dev.learnille.com/docs
- Swagger UI: Development environment API explorer
- OpenAPI JSON: https://api-dev.learnille.com/docs/openapi.json
API Architecture
RESTful Design Principles
- Resource-Based: APIs are organized around resources (users, courses, etc.)
- HTTP Methods: Standard HTTP methods (GET, POST, PUT, DELETE)
- Stateless: Each request contains all necessary information
- HATEOAS: Hypermedia as the Engine of Application State
Authentication
All API endpoints require authentication using JWT (JSON Web Tokens).
Authorization: Bearer <jwt_token>Token Acquisition
POST /auth/loginContent-Type: application/json
{ "email": "user@example.com", "password": "password"}Response:
{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "expires_in": 3600}API Versioning
- Current Version: v1
- Version Header:
Accept: application/vnd.learnille.v1+json - URL Versioning:
/api/v1/ - Deprecation Policy: 12 months notice for breaking changes
Core API Endpoints
User Management API
Get User Profile
GET /api/v1/users/{id}Authorization: Bearer {token}Update User Profile
PUT /api/v1/users/{id}Authorization: Bearer {token}Content-Type: application/json
{ "first_name": "John", "last_name": "Doe", "bio": "Learning enthusiast"}List Users
GET /api/v1/users?role=student&limit=20&offset=0Authorization: Bearer {token}Course Management API
List Courses
GET /api/v1/courses?category=programming&level=beginner&limit=10Get Course Details
GET /api/v1/courses/{id}Create Course
POST /api/v1/coursesAuthorization: Bearer {token}Content-Type: application/json
{ "title": "Introduction to React", "description": "Learn React fundamentals", "category_id": "uuid", "price": 49.99, "level": "beginner"}Update Course
PUT /api/v1/courses/{id}Authorization: Bearer {token}Content-Type: application/json
{ "title": "Advanced React", "is_published": true}Delete Course
DELETE /api/v1/courses/{id}Authorization: Bearer {token}Enrollment API
Enroll in Course
POST /api/v1/enrollmentsAuthorization: Bearer {token}Content-Type: application/json
{ "course_id": "uuid"}Get Enrollment Progress
GET /api/v1/enrollments/{id}/progressAuthorization: Bearer {token}Update Lesson Progress
PUT /api/v1/enrollments/{enrollment_id}/lessons/{lesson_id}/progressAuthorization: Bearer {token}Content-Type: application/json
{ "completed": true, "time_spent_minutes": 45}Payment API
Create Payment Intent
POST /api/v1/payments/intentAuthorization: Bearer {token}Content-Type: application/json
{ "amount": 49.99, "currency": "USD", "description": "Course enrollment"}Process Payment
POST /api/v1/payments/{id}/processAuthorization: Bearer {token}Content-Type: application/json
{ "payment_method_id": "pm_1234567890"}Get Payment History
GET /api/v1/payments?status=completed&limit=20Authorization: Bearer {token}Consultation API
List Available Consultations
GET /api/v1/consultations?category=programming&available=trueBook Consultation
POST /api/v1/consultations/{id}/bookAuthorization: Bearer {token}Content-Type: application/json
{ "scheduled_at": "2024-01-15T14:00:00Z"}Get Consultation Details
GET /api/v1/consultations/{id}Authorization: Bearer {token}Search API
Search Courses
GET /api/v1/search/courses?q=react&category=programming&level=beginnerSearch Users
GET /api/v1/search/users?q=john&role=instructorResponse Format
Success Response
{ "success": true, "data": { "id": "uuid", "name": "Example", "created_at": "2024-01-01T00:00:00Z" }, "meta": { "timestamp": "2024-01-01T00:00:00Z", "request_id": "req_123456" }}Error Response
{ "success": false, "error": { "code": "VALIDATION_ERROR", "message": "Invalid input data", "details": { "field": "email", "reason": "Invalid email format" } }, "meta": { "timestamp": "2024-01-01T00:00:00Z", "request_id": "req_123456" }}Rate Limiting
- Authenticated Requests: 1000 requests per hour
- Unauthenticated Requests: 100 requests per hour
- Search Requests: 50 requests per hour
Rate limit headers:
X-RateLimit-Limit: 1000X-RateLimit-Remaining: 999X-RateLimit-Reset: 1640995200Pagination
GET /api/v1/courses?limit=20&offset=0Response:
{ "success": true, "data": [...], "meta": { "pagination": { "total": 150, "limit": 20, "offset": 0, "has_more": true } }}Filtering and Sorting
Filtering
GET /api/v1/courses?category=programming&level=beginner&price_min=0&price_max=100Sorting
GET /api/v1/courses?sort=created_at&order=descGET /api/v1/courses?sort=rating&order=descWebhooks
Payment Webhooks
POST /api/v1/webhooks/stripeX-Signature: stripe_signature
{ "type": "payment_intent.succeeded", "data": { "object": { "id": "pi_1234567890", "amount": 4999, "currency": "usd" } }}SDKs and Libraries
JavaScript SDK
import { LearnilleAPI } from 'learnille-sdk';
const client = new LearnilleAPI({ apiKey: 'your-api-key', baseURL: 'https://api.learnille.com'});
// Get coursesconst courses = await client.courses.list({ category: 'programming', limit: 10});Python SDK
from learnille_sdk import LearnilleAPI
client = LearnilleAPI( api_key='your-api-key', base_url='https://api.learnille.com')
# Get coursescourses = client.courses.list(category='programming', limit=10)API Testing
Using cURL
# Get coursescurl -X GET "https://api.learnille.com/api/v1/courses" \ -H "Authorization: Bearer your-jwt-token"
# Create coursecurl -X POST "https://api.learnille.com/api/v1/courses" \ -H "Authorization: Bearer your-jwt-token" \ -H "Content-Type: application/json" \ -d '{"title": "New Course", "description": "Course description"}'Using Postman
- Import OpenAPI specification
- Set up environment variables for tokens
- Use collection runner for automated testing
Error Codes
| Code | Description |
|---|---|
| 400 | Bad Request - Invalid input |
| 401 | Unauthorized - Invalid/missing token |
| 403 | Forbidden - Insufficient permissions |
| 404 | Not Found - Resource doesn’t exist |
| 409 | Conflict - Resource already exists |
| 422 | Unprocessable Entity - Validation failed |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error - Server error |
Support
For API support and questions:
- Documentation: https://docs.learnille.com
- Developer Forum: https://community.learnille.com
- Email Support: api-support@learnille.com