SlideShare a Scribd company logo
TEAMING UP WP API & BACKBONE.JS
WHO KNOWS…
RFC 7230 - 7235
MAYBE THIS ONE…
RFC 2616
FAMILIAR WITH THIS?
HTTP
… AND THIS GUY?
-
RFC 7230 - 7235
=
RFC 2616
HTTPBIS
+
HTTPBIS
=
?
WHO THINKS HE/SHE KNOWS…?
REST
HTTP VERBS 101
CREATE POST SINGLE
RETRIEVE GET REPEATABLE
UPDATE PUT REPEATABLE
DELETE DELETE REPEATABLE
Teaming up WordPress API with Backbone.js in Titanium
HTTPS://WORDPRESS.ORG/PLUGINS/JSON-REST-API/
WP API
WP-API.ORG
COMPOSER REQUIRE WPACKAGIST/JSON-REST-API
/WP-JSON
{
"name": “A WP Site",
"description": "",
"URL": “https://www.a-wp-site.nl”,
"routes": {
"/": { ... },
"/posts": { ... },
"/posts/<id>": { ... },
...
"/users": { ... },
"/users/<id>": { ... },
"/users/me": { ... },
...
"/media": { ... }
},
"authentication": []
}
/WP-JSON (DETAIL)
{
...
"/posts/<id>": {
"supports": [
"HEAD",
"GET",
"POST",
"PUT",
"PATCH",
"DELETE"
],
"accepts_json": true
},
...
}
/WP-JSON/POSTS
POST /wp-json/posts HTTP/1.1
Host: www.a-wp-site.nl
Authorization: Basic anZitsafake6NjU0MzIx
Content-Type: application/x-www-form-urlencoded
title=test&content_raw=test
/WP-JSON/POSTS
§ POSTS
§ POST META
§ PAGES
§ USERS
§ MEDIA
§ TAXONOMIES
§ COMMENTS
OUT OF THE BOX SUPPORT
QUESTIONS?
THAT’S IT!
Teaming up WordPress API with Backbone.js in Titanium
PET PROJECT : KOOPHETLOKAAL
YOU KNOW HOW TO CREATE A PLUGIN?
EXTENDING THE API
MY PLUGIN.PHP SETUP
<?php
/*
Plugin Name: MY JSON API
Plugin URI: https://www.a-wp-site.nl/
Description: JSON REST API EXTENSION
Version: 1.0
Author: JRDK
Author URI: http://jrdk.nl
*/
require_once('src/Bootstrap.php');
new Bootstrap();
WHEN TO TRIGGER YOUR CODE
public function __construct()
{
add_action('plugins_loaded', [$this, 'initServer'], 100);
}
public function initServer()
{
if (!defined('JSON_API_VERSION')) {
// return early if WP API does not exist
add_action('all_admin_notices', [$this, 'showError']);
return;
}
}
ADD YOUR OWN CUSTOM POST TYPE
public function initServer()
{
//...
add_action('wp_json_server_before_serve', [$this, 'initEndpoints']);
}
public function initEndpoints($wp_json_server)
{
$ad = new Advertisement($wp_json_server);
}
class Advertisement extends WP_JSON_CustomPostType
{
protected $base = '/advertisements';
protected $type = 'advertisement';
}
/WP-JSON/VERSION/IOS
public function __construct()
{
add_filter('json_endpoints', [$this, 'registerRoutes']);
}
public function registerRoutes($routes)
{
$version_route = [
'/version/(?P<os>[a-z]{3,7})' => [
[
[$this, 'getVersion'],
WP_JSON_Server::READABLE
],
],
];
return array_merge($routes, $version_route);
}
FORGET IT ALL
WP API TEAM RUINED THIS TALK :)
IN A GOOD WAY
JSON != REST
IT COULD BE ANY OUTPUT
V2 REWRITE
CURRENTLY IN BETA
BACK TO THE PLUGIN SETUP
public function initServer()
{
if (!defined('JSON_API_VERSION') || !defined('REST_API_VERSION')) {
// return early if WP API versions do not exist
add_action('all_admin_notices', [$this, 'showError']);
return;
}
add_action('wp_json_server_before_serve', [$this, 'initEndpoints']);
add_filter('rest_url_prefix', [$this, 'changeApiBase']);
}
public function changeApiBase()
{
return 'api';
}
/API
{
"name": “A WP Site",
"description": "",
"URL": “https://www.a-wp-site.nl”,
"routes": {
"/": { ... },
“/wp/v2/posts”: { ... },
“/wp/v2/posts/<id>”: { ... },
...
“/wp/v2/users”: { ... },
“/wp/v2/users/<id>”: { ... },
“/wp/v2/users/me”: { ... },
...
“/wp/v2/media”: { ... }
},
"authentication": []
}
EXPOSE CUSTOM POST TYPE
public function initServer()
{
//...
add_action('init', [$this, 'updateExposure'], 12);
}
public function updateExposure()
{
global $wp_post_types;
$wp_post_types['advertisement']->show_in_rest = true;
$wp_post_types['advertisement']->rest_base = 'advertisement';
}
/API/KHL/VERSION/IOS
register_rest_route('khl', '/version/(?P<os>[a-z]{3,7})', [
'callback' => [$this, 'getVersion'],
'methods' => WP_REST_Server::READABLE,
'args' => [
'context' => [
'default' => 'view',
],
]]
);
Teaming up WordPress API with Backbone.js in Titanium
APPCELERATOR TITANIUM
VERY GLOBAL OVERVIEW
xml + tss + js ALLOY
JAVASCRIPT
TITANIUM SDK + your own modules
ANDROID IOS WINDOWS
BACKBONE.JS
SAVE POST CREATE
FETCH GET RETRIEVE
SAVE PUT UPDATE
DESTROY DELETE DELETE
THAT’S IT… AGAIN
var post = Backbone.Model.extend({
urlRoot: '/api/wp/v2/posts'
});
var posts = Backbone.Collection.extend({
model: post,
url: '/api/wp/v2/posts'
});
var newPost = new post({
title: ‘test',
content_raw: ‘test'
});
newPost.save();
BACKBONE TITANIUM EXTENSION
exports.definition = {
config : {
// table schema and adapter information
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// Extend, override or implement Backbone.Model
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// Extend, override or implement Backbone.Collection
});
return Collection;
}
}
CREATE SQLITE STORAGE WITH REST
exports.definition = {
config: {
columns: {
id: 'INTEGER PRIMARY KEY',
title: 'VARCHAR(50)',
image: ‘TEXT',
lastmodified: 'TEXT'
},
URL: 'https://www.a-wp-site.nl/api/khl/advertisements',
adapter: {
type: 'sqlrest',
collection_name: 'advertisements',
idAttribute: 'id'
}
}
//...
};
PARSE WORDPRESS API DATA
exports.definition = {
config: {
//...
parentNode: function(data) {
if (_.isArray(data)) {
var entries = [];
_.each(data, function (_entry, index) {
entries.push({
'id': _entry.ID,
'title': _entry.title,
'image': _entry.featured_image
});
});
return entries;
}
}
}
//...
};
ALLOY VIEW EXAMPLE
<Alloy>
<Collection src="advertisement"/>
<Window class="container">
<ListView id="listing">
<Templates>
<ItemTemplate name="fullItem">
<ImageView bindId="adImage" class="li-image" />
<Label bindId="title" class=“li-title"/>
</ItemTemplate>
</Templates>
<ListSection dataCollection="advertisement">
<ListItem template="fullItem" itemId="{id}"
title:text="{title}" adImage:image="{image}" />
</ListSection>
</ListView>
</Window>
</Alloy>
QUERY DATA FROM WORDPRESS
var advertisements = Alloy.Collections.instance(‘advertisement');
advertisements.fetch({
urlparams: {
filter: {
posts_per_page: 3,
orderby: {'date': 'DESC', 'ID': 'DESC'}
},
page: 1
},
sql: {
orderBy: 'timestamp DESC, id DESC'
},
success: function (col) {
}
});
IF MODIFIED SINCE
GET_LASTPOSTMODIFIED
UPLOADING A FILE
var bgImage = Ti.Filesystem.getFile('upload.jpg');
var xhr = Ti.Network.createHTTPClient();
xhr.timeout = 60000;
xhr.open('POST', '/api/wp/v2/media');
xhr.setRequestHeader('Authorization', '...');
xhr.setRequestHeader('Content-Type', 'image/jpeg');
xhr.setRequestHeader(
'Content-Disposition', 'attachment; filename=upload.jpg'
);
xhr.send(bgImage.read());
MAGIC MINUS
NEGATIVE INTEGERS
THE END RESULT
QUESTIONS?
JEROEN VAN DIJK
@JRVANDIJK
JEROEN@ENRISE.COM
JOIND.IN/13583
Teaming up WordPress API with Backbone.js in Titanium

More Related Content

Similar to Teaming up WordPress API with Backbone.js in Titanium (20)

PDF
Teaming up WordPress API with Backbone.js in Titanium
Jeroen van Dijk
 
PDF
WordPress REST API hacking
Jeroen van Dijk
 
PDF
JSON REST API for WordPress
Taylor Lovett
 
PPTX
The JSON REST API for WordPress
Taylor Lovett
 
PDF
WordPress REST API hacking
Jeroen van Dijk
 
PDF
JSON REST API for WordPress
Taylor Lovett
 
PPTX
WordPress Rest API
Brian Layman
 
PDF
WordPress as the Backbone(.js)
Beau Lebens
 
PDF
Using the new WordPress REST API
Caldera Labs
 
PDF
WORDPRESS_REST_API_WORDPRESS_REST_API.pdf
Angy668409
 
PPTX
Using WordPress as your application stack
Paul Bearne
 
PDF
Caldera Learn - LoopConf WP API + Angular FTW Workshop
CalderaLearn
 
PPT
nguyenhainhathuy-building-restful-web-service
hazzaz
 
KEY
Representation state transfer and some other important stuff
Joshua Thijssen
 
PDF
Demystifying REST - SFRails meetup
Kirsten Hunter
 
PPTX
WP REST API - Building a simple Web Application
Edmund Chan
 
PDF
Rest
Brian Kaney
 
PDF
SunShine PHP
David Bisset
 
PPTX
The WordPress REST API as a Springboard for Website Greatness
WP Engine UK
 
PPTX
Let's code_ WP REST API - custom routes and endpoints.pptx
Jonathan Bossenger
 
Teaming up WordPress API with Backbone.js in Titanium
Jeroen van Dijk
 
WordPress REST API hacking
Jeroen van Dijk
 
JSON REST API for WordPress
Taylor Lovett
 
The JSON REST API for WordPress
Taylor Lovett
 
WordPress REST API hacking
Jeroen van Dijk
 
JSON REST API for WordPress
Taylor Lovett
 
WordPress Rest API
Brian Layman
 
WordPress as the Backbone(.js)
Beau Lebens
 
Using the new WordPress REST API
Caldera Labs
 
WORDPRESS_REST_API_WORDPRESS_REST_API.pdf
Angy668409
 
Using WordPress as your application stack
Paul Bearne
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
CalderaLearn
 
nguyenhainhathuy-building-restful-web-service
hazzaz
 
Representation state transfer and some other important stuff
Joshua Thijssen
 
Demystifying REST - SFRails meetup
Kirsten Hunter
 
WP REST API - Building a simple Web Application
Edmund Chan
 
SunShine PHP
David Bisset
 
The WordPress REST API as a Springboard for Website Greatness
WP Engine UK
 
Let's code_ WP REST API - custom routes and endpoints.pptx
Jonathan Bossenger
 

More from Jeroen van Dijk (13)

PDF
The Enterprise Wor/d/thy/Press
Jeroen van Dijk
 
PDF
The Enterprise Wor/d/thy/Press
Jeroen van Dijk
 
PDF
Beacons in Appcelerator Titanium
Jeroen van Dijk
 
PDF
An app on the shoulders of giants
Jeroen van Dijk
 
PDF
Zend Server: Not just a PHP stack
Jeroen van Dijk
 
PDF
Refactoring using Codeception
Jeroen van Dijk
 
PDF
Liking Relevance - PHP North East 2014
Jeroen van Dijk
 
PDF
To SQL or No(t)SQL - PHPNW12
Jeroen van Dijk
 
PDF
To SQL or No(t)SQL - PFCongres 2012
Jeroen van Dijk
 
PDF
Socializing a world of travel
Jeroen van Dijk
 
PDF
Varnish, the high performance valhalla?
Jeroen van Dijk
 
PPTX
Varnish, the high performance valhalla?
Jeroen van Dijk
 
PPTX
Edge Side Includes in Zend Framework without Varnish
Jeroen van Dijk
 
The Enterprise Wor/d/thy/Press
Jeroen van Dijk
 
The Enterprise Wor/d/thy/Press
Jeroen van Dijk
 
Beacons in Appcelerator Titanium
Jeroen van Dijk
 
An app on the shoulders of giants
Jeroen van Dijk
 
Zend Server: Not just a PHP stack
Jeroen van Dijk
 
Refactoring using Codeception
Jeroen van Dijk
 
Liking Relevance - PHP North East 2014
Jeroen van Dijk
 
To SQL or No(t)SQL - PHPNW12
Jeroen van Dijk
 
To SQL or No(t)SQL - PFCongres 2012
Jeroen van Dijk
 
Socializing a world of travel
Jeroen van Dijk
 
Varnish, the high performance valhalla?
Jeroen van Dijk
 
Varnish, the high performance valhalla?
Jeroen van Dijk
 
Edge Side Includes in Zend Framework without Varnish
Jeroen van Dijk
 
Ad

Recently uploaded (20)

PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Ad

Teaming up WordPress API with Backbone.js in Titanium

  • 1. TEAMING UP WP API & BACKBONE.JS
  • 6. - RFC 7230 - 7235 = RFC 2616 HTTPBIS
  • 8. WHO THINKS HE/SHE KNOWS…? REST
  • 9. HTTP VERBS 101 CREATE POST SINGLE RETRIEVE GET REPEATABLE UPDATE PUT REPEATABLE DELETE DELETE REPEATABLE
  • 12. /WP-JSON { "name": “A WP Site", "description": "", "URL": “https://www.a-wp-site.nl”, "routes": { "/": { ... }, "/posts": { ... }, "/posts/<id>": { ... }, ... "/users": { ... }, "/users/<id>": { ... }, "/users/me": { ... }, ... "/media": { ... } }, "authentication": [] }
  • 13. /WP-JSON (DETAIL) { ... "/posts/<id>": { "supports": [ "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE" ], "accepts_json": true }, ... }
  • 14. /WP-JSON/POSTS POST /wp-json/posts HTTP/1.1 Host: www.a-wp-site.nl Authorization: Basic anZitsafake6NjU0MzIx Content-Type: application/x-www-form-urlencoded title=test&content_raw=test
  • 16. § POSTS § POST META § PAGES § USERS § MEDIA § TAXONOMIES § COMMENTS OUT OF THE BOX SUPPORT
  • 19. PET PROJECT : KOOPHETLOKAAL
  • 20. YOU KNOW HOW TO CREATE A PLUGIN? EXTENDING THE API
  • 21. MY PLUGIN.PHP SETUP <?php /* Plugin Name: MY JSON API Plugin URI: https://www.a-wp-site.nl/ Description: JSON REST API EXTENSION Version: 1.0 Author: JRDK Author URI: http://jrdk.nl */ require_once('src/Bootstrap.php'); new Bootstrap();
  • 22. WHEN TO TRIGGER YOUR CODE public function __construct() { add_action('plugins_loaded', [$this, 'initServer'], 100); } public function initServer() { if (!defined('JSON_API_VERSION')) { // return early if WP API does not exist add_action('all_admin_notices', [$this, 'showError']); return; } }
  • 23. ADD YOUR OWN CUSTOM POST TYPE public function initServer() { //... add_action('wp_json_server_before_serve', [$this, 'initEndpoints']); } public function initEndpoints($wp_json_server) { $ad = new Advertisement($wp_json_server); } class Advertisement extends WP_JSON_CustomPostType { protected $base = '/advertisements'; protected $type = 'advertisement'; }
  • 24. /WP-JSON/VERSION/IOS public function __construct() { add_filter('json_endpoints', [$this, 'registerRoutes']); } public function registerRoutes($routes) { $version_route = [ '/version/(?P<os>[a-z]{3,7})' => [ [ [$this, 'getVersion'], WP_JSON_Server::READABLE ], ], ]; return array_merge($routes, $version_route); }
  • 26. WP API TEAM RUINED THIS TALK :)
  • 27. IN A GOOD WAY
  • 28. JSON != REST IT COULD BE ANY OUTPUT
  • 30. BACK TO THE PLUGIN SETUP public function initServer() { if (!defined('JSON_API_VERSION') || !defined('REST_API_VERSION')) { // return early if WP API versions do not exist add_action('all_admin_notices', [$this, 'showError']); return; } add_action('wp_json_server_before_serve', [$this, 'initEndpoints']); add_filter('rest_url_prefix', [$this, 'changeApiBase']); } public function changeApiBase() { return 'api'; }
  • 31. /API { "name": “A WP Site", "description": "", "URL": “https://www.a-wp-site.nl”, "routes": { "/": { ... }, “/wp/v2/posts”: { ... }, “/wp/v2/posts/<id>”: { ... }, ... “/wp/v2/users”: { ... }, “/wp/v2/users/<id>”: { ... }, “/wp/v2/users/me”: { ... }, ... “/wp/v2/media”: { ... } }, "authentication": [] }
  • 32. EXPOSE CUSTOM POST TYPE public function initServer() { //... add_action('init', [$this, 'updateExposure'], 12); } public function updateExposure() { global $wp_post_types; $wp_post_types['advertisement']->show_in_rest = true; $wp_post_types['advertisement']->rest_base = 'advertisement'; }
  • 33. /API/KHL/VERSION/IOS register_rest_route('khl', '/version/(?P<os>[a-z]{3,7})', [ 'callback' => [$this, 'getVersion'], 'methods' => WP_REST_Server::READABLE, 'args' => [ 'context' => [ 'default' => 'view', ], ]] );
  • 36. VERY GLOBAL OVERVIEW xml + tss + js ALLOY JAVASCRIPT TITANIUM SDK + your own modules ANDROID IOS WINDOWS
  • 38. SAVE POST CREATE FETCH GET RETRIEVE SAVE PUT UPDATE DESTROY DELETE DELETE
  • 39. THAT’S IT… AGAIN var post = Backbone.Model.extend({ urlRoot: '/api/wp/v2/posts' }); var posts = Backbone.Collection.extend({ model: post, url: '/api/wp/v2/posts' }); var newPost = new post({ title: ‘test', content_raw: ‘test' }); newPost.save();
  • 40. BACKBONE TITANIUM EXTENSION exports.definition = { config : { // table schema and adapter information }, extendModel: function(Model) { _.extend(Model.prototype, { // Extend, override or implement Backbone.Model }); return Model; }, extendCollection: function(Collection) { _.extend(Collection.prototype, { // Extend, override or implement Backbone.Collection }); return Collection; } }
  • 41. CREATE SQLITE STORAGE WITH REST exports.definition = { config: { columns: { id: 'INTEGER PRIMARY KEY', title: 'VARCHAR(50)', image: ‘TEXT', lastmodified: 'TEXT' }, URL: 'https://www.a-wp-site.nl/api/khl/advertisements', adapter: { type: 'sqlrest', collection_name: 'advertisements', idAttribute: 'id' } } //... };
  • 42. PARSE WORDPRESS API DATA exports.definition = { config: { //... parentNode: function(data) { if (_.isArray(data)) { var entries = []; _.each(data, function (_entry, index) { entries.push({ 'id': _entry.ID, 'title': _entry.title, 'image': _entry.featured_image }); }); return entries; } } } //... };
  • 43. ALLOY VIEW EXAMPLE <Alloy> <Collection src="advertisement"/> <Window class="container"> <ListView id="listing"> <Templates> <ItemTemplate name="fullItem"> <ImageView bindId="adImage" class="li-image" /> <Label bindId="title" class=“li-title"/> </ItemTemplate> </Templates> <ListSection dataCollection="advertisement"> <ListItem template="fullItem" itemId="{id}" title:text="{title}" adImage:image="{image}" /> </ListSection> </ListView> </Window> </Alloy>
  • 44. QUERY DATA FROM WORDPRESS var advertisements = Alloy.Collections.instance(‘advertisement'); advertisements.fetch({ urlparams: { filter: { posts_per_page: 3, orderby: {'date': 'DESC', 'ID': 'DESC'} }, page: 1 }, sql: { orderBy: 'timestamp DESC, id DESC' }, success: function (col) { } });
  • 46. UPLOADING A FILE var bgImage = Ti.Filesystem.getFile('upload.jpg'); var xhr = Ti.Network.createHTTPClient(); xhr.timeout = 60000; xhr.open('POST', '/api/wp/v2/media'); xhr.setRequestHeader('Authorization', '...'); xhr.setRequestHeader('Content-Type', 'image/jpeg'); xhr.setRequestHeader( 'Content-Disposition', 'attachment; filename=upload.jpg' ); xhr.send(bgImage.read());