Developer Guide

REST API & Data Access (Advanced Integration Guide)

Estimated reading: 4 minutes 45 views

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:

MethodBase URLAuthUse Case
REST API/wp-json/Nonce / CookieFetch content, stream video
AJAX API/wp-admin/admin-ajax.phpNonceFiltering, search, user actions
Frontend JS DatamovieEngineDataโ€”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).

ParamTypeRequiredDescription
idintโœ…Post ID
indexintโŒSource index
_wpnoncestringโœ…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.

ParamTypeRequired
idintโœ…
indexintโœ…
_wpnoncestringโœ…

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 TypeEndpointDescription
Movies/wp/v2/movie_engine_movieMovie list
Series/wp/v2/movie_engine_seriesSeries list
Episodes/wp/v2/movie_engine_episodeEpisode data
Seasons/wp/v2/movie_engine_seasonSeason data
People/wp/v2/movie_engine_personCast & crew

Example

GET /wp-json/wp/v2/movie_engine_movie?per_page=10

๐Ÿท Taxonomies

Used for filtering and categorization.

TaxonomyEndpoint
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.

ActionMethodPurpose
movie_engine_filter_moviesGETFilter content
movie_engine_get_filter_termsGETLoad filter data
movie_engine_load_more_episodesGETLoad episodes
movie_engine_get_video_sourcePOSTGet sources
movie_engine_track_viewPOSTTrack views
movie_engine_live_searchGETSearch
movie_engine_fetch_reviewsGETLoad reviews

๐Ÿ” User Actions (Login Required)

Used for personalized features.

ActionMethodPurpose
movie_engine_mark_watchedPOSTSave progress
movie_engine_toggle_likePOSTLike content
movie_engine_get_notificationsGETFetch notifications
movie_engine_get_history_pageGETWatch history
movie_engine_get_watchlist_pageGETWatchlist
movie_engine_get_playlists_pageGETPlaylists

๐Ÿง  Frontend JavaScript Data

Movie Engine provides localized JS objects for frontend usage.

๐Ÿ“ฆ movieEngineData

Available globally on frontend pages.

KeyDescription
ajax_urlAJAX endpoint
rest_urlREST base URL
stream_urlStream endpoint
nonceAJAX nonce
rest_nonceREST nonce
userCurrent user
is_premiumPremium status
player_settingsPlayer config

๐Ÿ‘‰ Filter: movie_engine_frontend_data

๐Ÿ“Š movieEngineDashboard

Used in dashboard pages.

KeyDescription
ajax_urlAJAX endpoint
nonceSecurity nonce
logged_inUser status
login_urlLogin 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) and wp_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

LayerPurpose
REST APIContent & streaming
AJAXDynamic UI actions
JS DataFrontend config

Share this Doc

REST API & Data Access (Advanced Integration Guide)

Or copy link

CONTENTS