REST API & Data Access (Advanced Integration Guide)
This guide explains how to access and interact with Movie Engine data using REST API, AJAX, and JavaScript, enabling advanced integrations such as:
- Headless applications
- Mobile apps
- Custom players
- Third-party services
๐ Overview
Movie Engine provides three main data access layers:
| Method | Base URL | Auth | Use Case |
|---|---|---|---|
| REST API | /wp-json/ | Nonce / Cookie | Fetch content, stream video |
| AJAX API | /wp-admin/admin-ajax.php | Nonce | Filtering, search, user actions |
| Frontend JS Data | movieEngineData | โ | Config, URLs, runtime data |
๐ REST API
The REST API allows you to fetch content and stream media programmatically.
Base Endpoint
https://yoursite.com/wp-json/movie-engine/v1/
๐ฌ Custom Endpoints
These endpoints are provided by Movie Engine for media delivery.
โถ๏ธ Video Stream Endpoint
Endpoint
GET /movie-engine/v1/stream/{id}
Purpose
Streams or redirects to the video source (MP4, HLS, or embed).
| Param | Type | Required | Description |
|---|---|---|---|
id | int | โ | Post ID |
index | int | โ | Source index |
_wpnonce | string | โ | REST nonce |
Example
GET /wp-json/movie-engine/v1/stream/123?_wpnonce=xxx
Use Case
- Custom video player
- Mobile streaming app
- OTT frontend
๐ Subtitle Proxy Endpoint
Endpoint
GET /movie-engine/v1/subtitle/{id}/{index}
Purpose
Proxies subtitle files (VTT) to avoid CORS issues.
| Param | Type | Required |
|---|---|---|
id | int | โ |
index | int | โ |
_wpnonce | string | โ |
Example
GET /wp-json/movie-engine/v1/subtitle/123/0?_wpnonce=xxx
๐ฆ WordPress REST API (Content Access)
Movie Engine registers all post types and taxonomies with:
show_in_rest => true
So you can use standard WordPress endpoints.
๐ฅ Post Types
These endpoints return structured content data.
| Post Type | Endpoint | Description |
|---|---|---|
| Movies | /wp/v2/movie_engine_movie | Movie list |
| Series | /wp/v2/movie_engine_series | Series list |
| Episodes | /wp/v2/movie_engine_episode | Episode data |
| Seasons | /wp/v2/movie_engine_season | Season data |
| People | /wp/v2/movie_engine_person | Cast & crew |
Example
GET /wp-json/wp/v2/movie_engine_movie?per_page=10
๐ท Taxonomies
Used for filtering and categorization.
| Taxonomy | Endpoint |
|---|---|
| Genre | /wp/v2/movie_engine_genre |
| Year | /wp/v2/movie_engine_year |
| Quality | /wp/v2/movie_engine_quality |
| Country | /wp/v2/movie_engine_country |
| Language | /wp/v2/movie_engine_language |
| Tag | /wp/v2/movie_engine_tag |
โก AJAX API
The AJAX API is used for dynamic frontend interactions without page reload.
Endpoint
/wp-admin/admin-ajax.php
๐ Public Actions (No Login Required)
Used for browsing and content interaction.
| Action | Method | Purpose |
|---|---|---|
movie_engine_filter_movies | GET | Filter content |
movie_engine_get_filter_terms | GET | Load filter data |
movie_engine_load_more_episodes | GET | Load episodes |
movie_engine_get_video_source | POST | Get sources |
movie_engine_track_view | POST | Track views |
movie_engine_live_search | GET | Search |
movie_engine_fetch_reviews | GET | Load reviews |
๐ User Actions (Login Required)
Used for personalized features.
| Action | Method | Purpose |
|---|---|---|
movie_engine_mark_watched | POST | Save progress |
movie_engine_toggle_like | POST | Like content |
movie_engine_get_notifications | GET | Fetch notifications |
movie_engine_get_history_page | GET | Watch history |
movie_engine_get_watchlist_page | GET | Watchlist |
movie_engine_get_playlists_page | GET | Playlists |
๐ง Frontend JavaScript Data
Movie Engine provides localized JS objects for frontend usage.
๐ฆ movieEngineData
Available globally on frontend pages.
| Key | Description |
|---|---|
ajax_url | AJAX endpoint |
rest_url | REST base URL |
stream_url | Stream endpoint |
nonce | AJAX nonce |
rest_nonce | REST nonce |
user | Current user |
is_premium | Premium status |
player_settings | Player config |
๐ Filter: movie_engine_frontend_data
๐ movieEngineDashboard
Used in dashboard pages.
| Key | Description |
|---|---|
ajax_url | AJAX endpoint |
nonce | Security nonce |
logged_in | User status |
login_url | Login link |
๐ Filter: movie_engine_dashboard_data
๐ Authentication
REST API
- Cookie authentication (logged-in users)
- REST nonce (
wp_rest) - Application passwords (for headless apps)
AJAX
- Requires
movie_engine_nonce - Uses
wp_ajax_*(authenticated) andwp_ajax_nopriv_*(public)
Generate Nonce
PHP
wp_create_nonce('movie_engine_nonce');
wp_create_nonce('wp_rest');
JavaScript
movieEngineData.nonce
movieEngineData.rest_nonce
๐งช Usage Examples
1. Fetch Movies (REST)
fetch('/wp-json/wp/v2/movie_engine_movie?per_page=12')
.then(r => r.json())
.then(data => console.log(data));
2. Filter Movies (AJAX)
fetch(`${movieEngineData.ajax_url}?action=movie_engine_filter_movies&nonce=${movieEngineData.nonce}`)
.then(r => r.text())
.then(html => document.getElementById('grid').innerHTML = html);
3. Live Search
fetch(`${movieEngineData.ajax_url}?action=movie_engine_live_search&nonce=${movieEngineData.nonce}&s=test`)
.then(r => r.json())
.then(data => console.log(data));
4. Stream Video
const url = `${movieEngineData.stream_url}123?_wpnonce=${movieEngineData.rest_nonce}`;
๐ฏ Use Cases
- ๐ฑ Build mobile OTT apps
- ๐ฌ Create custom video players
- ๐ Headless WordPress frontend
- ๐ Integrate third-party systems
- โก Build SPA (React/Vue)
๐ Security Best Practices
- Validate nonce on all requests
- Restrict stream endpoint to same-origin
- Use signed URLs for secure streaming
- Avoid exposing raw video URLs
- Sanitize all inputs
๐ Summary
| Layer | Purpose |
|---|---|
| REST API | Content & streaming |
| AJAX | Dynamic UI actions |
| JS Data | Frontend config |
