SlideShare une entreprise Scribd logo
1  sur  48
WordPress APIs
Feeds, XML-RPC, APP, and “REST”



  WordCamp OC - 2012/06/02 - Mike Adams
Hi
• Mike Adams = mdawaffe
• Automattic/WordPress.com: ~6 years
• WordPress developer: ~8 years
• Team Social Lead
Hi
• Mike Adams = mdawaffe
• Automattic/WordPress.com: ~6 years
• WordPress developer: ~8 years
• Team Social Lead
       Links/Examples:
       wp.me/p1s-3Z
       pee one ess dash three ZEE
WordPress Data
      over HTTP
• Feeds
• XML-RPC
• Atom Publishing Protocol
• “REST”
Evaluating
• Provides useful data/ways to manipulate
• Is easy to work with in any language
• Well documented
• Grokkable (human readable)
• Command line is king
Feeds
• RSS v. Atom: essentially the same
• Historically, RSS has gotten more love
Feeds: Features
• Get
 • Posts, Pages
 • Comments
• Can use normal WordPress query args
  author_name=mdawaffe,
  search=wordpress,
  category_name=goats, page=2, ...
Feeds: Tools
• Command Line: curl
• PHP: SimplePie
  http://simplepie.org/

• WordPress: fetch_feed()
  Simple wrapper for SimplePie
• JS: It’s just XML?
  DOM, jQuery, ...
Feeds: Examples
• Via JS, get most recent post titles:
  jsfiddle.net/mdawaffe/ZQn5c/
• Via CLI, get URL of most recent post:
  curl example.com/feed/ |
  perl -pe 'BEGIN{$/=undef}
  s/.*?<item>.*?<link>(.*?)<.*
  /$1/s'
  Not really CLI if you resort to Perl :)
Feeds: Examples
• Count posts by Marla that contain the
  string “movie”.
  curl example.com/feed/
  ?author_name=marla
  &search=movie
    | grep '<item>'
    | wc -l
  Nope: Won’t work
Feeds: Caveats
• Not always a perfect representation of
  for-display content
• Never a good representation of
  for-edit content
• Pagination
• Plugins that add structured data to feeds
  may only touch RSS (not Atom)
Feeds: Evaluation
• Data: Posts, Comments Only. Read Only
• Easy: Meh - Libraries
• Docs: Lots of specs
• Grok: Mostly
• CLI: Not so easy
Feeds: Conclusion
• Quick way of reading basic data, but caveats
• Longstanding, standard formats
• Parsers available in every language
• For WordPress, RSS > Atom
XML-RPC
• Remote Procedure Call = Function based
• Developed by Dave Winer in 1999
• xmlrpc.scripting.com/spec.html
XML-RPC: Request
POST /xmlrpc.php HTTP/1.1
HOST: example.com
Content-Type: text/xml
Content-Length: 311
<?xml version="1.0"?>
<methodCall>
<methodName>wp.getPosts</methodName>
<params>
 <param>
  <value>
  <array>
   <data>
    <value><int>0</int></value>
    <value><string>username</string></value>
    <value><string>password</string></value>
   </data>
  </array>
  </value>
 </param>
</params>
</methodCall>
XML-RPC: Response
HTTP/1.1 200 OK
Content-Type: text/xml
Content-Length: 27000
<?xml version="1.0"?>
<methodResponse>
 <params>
  <param>
  <value>
   <array>
    <data>
     <value>
     <struct>
      <member><name>post_id</name><value><string>26</
string></value></member>
      <member><name>post_title</name><value><string>Space
Monkey!</string></value></member>
      ...
     </struct>
     </value>
     <value>
     ...
XML-RPC: WordPress
• WordPress offers considerable
  functionality: Read and Write
• Requires Authentication
• Supported on all WordPress sites
  (Opt-in for non-WordPress.com sites)
• Poorly Documented
• Highly Extensible (via Plugin)
XML-RPC: Features
• Get/Create/Edit/Delete
 • Posts, Pages
 • Comments
 • Terms, Taxonomies
 • Options
• Media Uploads
XML-RPC: Auth
• All (most) XML-RPC calls require
  authentication
• WordPress.ORG
 • Username/Password
 • Extensible via Plugin
XML-RPC: Auth
• All (most) XML-RPC calls require
  authentication
• WordPress.COM
 • Username/Password
 • OAuth2
XML-RPC: Docs
• XML-RPC is just a communication spec
• Standard sets of Remote Procedures:
  Blogger, MoveableType, MetaWeblog, ...
• WordPress supports them all!
• codex.wordpress.org/XML-RPC_Support
• wp-includes/class-wp-xmlrpc-server.php
XML-RPC: Extensible
• New Remote Procedures can be added
  with the xmlrpc_methods filter
• Hooked function:
 • accepts array of arguments
 • returns most anything
• XML parsing/serializing done by WordPress
XML-RPC: Tools
• Command Line: Hard
• PHP: xmlrpc_encode_request()
• WordPress: WP_HTTP_IXR_Client
• JS: Mimic mimic-xmlrpc.sourceforge.net
XML-RPC: Example
$x = new WP_HTTP_IXR_Client($URL);
$x->query( ‘wp.newPage’, array(
 0, ‘user’, ‘password’,
 array(
  ‘title’ => ‘WordCamp’,
  ‘description’ => ‘OC, Baby!’
 ),
 1,
));
XML-RPC: Caveats
• Never a true representation of for-display
  content
• Usually a true representation of for-edit
  content
• Pagination impossible (until 3.4)
XML-RPC: Evaluation
• Data: Lots of functionality
• Easy: Meh - Libraries
• Docs: No
• Grok: No
• CLI: No
XML-RPC: Conclusion
• Pros
 • WordPress offers lots of functionality
 • Easy to extend
• Cons
 • Caveats
 • Verbose XML
 • Poorly Documented
APP
• Atom Publishing Protocol
• RESTful - object based
• Posts are represented as Atom Feed entries
• tools.ietf.org/html/rfc5023
APP: WordPress
• WordPress offers limited functionality
• Requires Authentication
• Supported on all WordPress sites
  (Opt-in for non-WordPress.com sites)
• Poorly Documented
• Harder to extend than XML-RPC
APP: Features
• Get/Create/Edit/Delete
 • Posts, Pages
• Media Uploads
APP: Auth
• All APP calls require authentication
 • BASIC (Username/Password)
 • Extensible via Plugin
APP: Example
APP: Example


     ...
APP: Evaluation
• Data: Posts only
• Easy: Not really. At least it’s XML.
• Docs: No
• Grok: Looks like a feed
• CLI: No
APP: Conclusion
• Pro: Aesthetically cool
• Cons
 • Not very well supported in WordPress
 • Hard to extend
 • Poorly documented
• Don’t bother unless you are heavily
  invested in APP elsewhere already
“REST”ful JSON
• WordPress.COM has launched a new
  RESTful JSON API
• Soon in Jetpack
• Will likely be in core (3.6?)
“REST”ful JSON
• Fairly full featured
• Public data does not require authentication
• Private data requires OAuth2
• True representation of both
  for-display, and for-edit content
• Well documented
JSON: Features
• Get/Create/Edit/Delete
 • Posts, Pages
 • Comments
 • Terms, Taxonomies
• Media Uploads
JSON: “REST”
https://public-api.wordpress.com/rest/v1/sites/$site

  • Read: GET /posts/$post_id
  • Create: POST /posts/new
  • Update: POST /posts/$post_id
  • Delete: POST /posts/$post_id/delete
  POST requests can be JSON or form encoded
JSON: Docs
• Dynamically generated: always up to date
• developer.wordpress.com/docs/api/
• Append “/help” to any API URL
• API Console: AMAZING!
  developer.wordpress.com/docs/api/console/
JSON: Tools
• Command Line: curl
• PHP: file_get_contents()
• WordPress: wp_remote_request()
• JS:Yes
• Any language that can make remote HTTP
  requests and understand JSON(P)
JSON: Examples
• Get most recent post
  public-api.wordpress.com/rest/v1/sites/
    en.blog.wordpress.com/posts/?number=1
    jsfiddle.net/mdawaffe/hLWdH/
•   Get a post’s likes
    public-api.wordpress.com/rest/v1/sites/
    en.blog.wordpress.com/posts/11235/likes/
    jsfiddle.net/mdawaffe/QgPqV/
JSON: Examples
• Create a Post
  curl --data 'title=WCOC'
       --data 'content=Rocks'
       -H 'Authorization:
            BEARER *SECRET*'
  https://public-
  api.wordpress.com/rest/v1/
  sites/mdawaffe.wordpress.com/
  posts/new
JSON: Evaluation
• Data: Not as fully featured as XML-RPC
• Easy:Yes
• Docs:Yes!
• Grok:Yes
• CLI:Yes!
JSON: Conclusion
• Pros
 • Easiest to use
 • Built in up-to-date documentation
 • True representation of for-display and
    for-edit content
• Con:
 • Not as full featured as XML-RPC (yet!)
Bye
• Mike Adams = mdawaffe
Bye
• Mike Adams = mdawaffe
• Thanks!
WordPress APIs

Contenu connexe

Tendances

Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsTaylor Lovett
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress developmentSteve Mortiboy
 
PowerShell for sharepoint 2010 administrators
PowerShell for sharepoint 2010 administratorsPowerShell for sharepoint 2010 administrators
PowerShell for sharepoint 2010 administratorsRavikanth Chaganti
 
You Got React.js in My PHP
You Got React.js in My PHPYou Got React.js in My PHP
You Got React.js in My PHPTaylor Lovett
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressRami Sayar
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchTaylor Lovett
 
Untangling spring week9
Untangling spring week9Untangling spring week9
Untangling spring week9Derek Jacoby
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11Derek Jacoby
 
5 Things You Shouldn't Do With A WordPress Plugin
5 Things You Shouldn't Do With A WordPress Plugin5 Things You Shouldn't Do With A WordPress Plugin
5 Things You Shouldn't Do With A WordPress PluginKelly Phillips
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Mike Schinkel
 
NEPA BlogCon 2013 - WordPress Customization & Security
NEPA BlogCon 2013 - WordPress Customization & SecurityNEPA BlogCon 2013 - WordPress Customization & Security
NEPA BlogCon 2013 - WordPress Customization & SecurityMichelle Davies (Hryvnak)
 
PowerShell and SharePoint
PowerShell and SharePointPowerShell and SharePoint
PowerShell and SharePointTalbott Crowell
 
Untangling spring week10
Untangling spring week10Untangling spring week10
Untangling spring week10Derek Jacoby
 
WordPress Customization and Security
WordPress Customization and SecurityWordPress Customization and Security
WordPress Customization and SecurityJoe Casabona
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPressMicah Wood
 
SharePoint Development 101
SharePoint Development 101SharePoint Development 101
SharePoint Development 101Greg Hurlman
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsSauce Labs
 
WordPress Rest API
WordPress Rest APIWordPress Rest API
WordPress Rest APIBrian Layman
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersBoulos Dib
 

Tendances (20)

Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
PowerShell for sharepoint 2010 administrators
PowerShell for sharepoint 2010 administratorsPowerShell for sharepoint 2010 administrators
PowerShell for sharepoint 2010 administrators
 
You Got React.js in My PHP
You Got React.js in My PHPYou Got React.js in My PHP
You Got React.js in My PHP
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
 
Untangling spring week9
Untangling spring week9Untangling spring week9
Untangling spring week9
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11
 
5 Things You Shouldn't Do With A WordPress Plugin
5 Things You Shouldn't Do With A WordPress Plugin5 Things You Shouldn't Do With A WordPress Plugin
5 Things You Shouldn't Do With A WordPress Plugin
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 
NEPA BlogCon 2013 - WordPress Customization & Security
NEPA BlogCon 2013 - WordPress Customization & SecurityNEPA BlogCon 2013 - WordPress Customization & Security
NEPA BlogCon 2013 - WordPress Customization & Security
 
PowerShell and SharePoint
PowerShell and SharePointPowerShell and SharePoint
PowerShell and SharePoint
 
Fluxible
FluxibleFluxible
Fluxible
 
Untangling spring week10
Untangling spring week10Untangling spring week10
Untangling spring week10
 
WordPress Customization and Security
WordPress Customization and SecurityWordPress Customization and Security
WordPress Customization and Security
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPress
 
SharePoint Development 101
SharePoint Development 101SharePoint Development 101
SharePoint Development 101
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
 
WordPress Rest API
WordPress Rest APIWordPress Rest API
WordPress Rest API
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint Developers
 

En vedette

Core plugins - WordCamp UK 2010
Core plugins  - WordCamp UK 2010Core plugins  - WordCamp UK 2010
Core plugins - WordCamp UK 2010Peter Westwood
 
State of the Word 2016
State of the Word 2016State of the Word 2016
State of the Word 2016photomatt
 
Design in Tech Report 2017
Design in Tech Report 2017Design in Tech Report 2017
Design in Tech Report 2017John Maeda
 
Wordcamp 2010 I'm A Scientist Get me Out of Here - Mike Little
Wordcamp 2010 I'm A Scientist Get me Out of Here - Mike LittleWordcamp 2010 I'm A Scientist Get me Out of Here - Mike Little
Wordcamp 2010 I'm A Scientist Get me Out of Here - Mike LittleMike Little
 
WordPress as a Service
WordPress as a ServiceWordPress as a Service
WordPress as a ServiceAndrew Bauer
 
Empowering Your Clients and Be an Advocate for Yourself
Empowering Your Clients and Be an Advocate for YourselfEmpowering Your Clients and Be an Advocate for Yourself
Empowering Your Clients and Be an Advocate for YourselfLinchpin
 
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...Sergio Costa
 
Comunidade. Abuse e use dela com moderação e inteligência.
Comunidade. Abuse e use dela com moderação e inteligência.Comunidade. Abuse e use dela com moderação e inteligência.
Comunidade. Abuse e use dela com moderação e inteligência.Beto Muniz
 
Sweet Child O' Themes
Sweet Child O' ThemesSweet Child O' Themes
Sweet Child O' ThemesBreno Alves
 
Do marketplace ao WordPress - WordCamp BH 2015
Do marketplace ao WordPress -  WordCamp BH 2015Do marketplace ao WordPress -  WordCamp BH 2015
Do marketplace ao WordPress - WordCamp BH 2015Fellyph Cintra
 
Debugging WordPress Core and Plugins!
Debugging WordPress Core and Plugins!Debugging WordPress Core and Plugins!
Debugging WordPress Core and Plugins!Bronson Quick
 
Never fear, the customizer is here!
Never fear, the customizer is here!Never fear, the customizer is here!
Never fear, the customizer is here!Cameron Jones
 
Getting to Know Underscores
Getting to Know Underscores Getting to Know Underscores
Getting to Know Underscores Jason Yingling
 
Teresa Lane - Content Modeling - WordCamp St. Louis 2016
Teresa Lane - Content Modeling - WordCamp St. Louis 2016Teresa Lane - Content Modeling - WordCamp St. Louis 2016
Teresa Lane - Content Modeling - WordCamp St. Louis 2016Teresa Lane
 
Create a newsletter in less than 17 minutes without writing a single word
Create a newsletter in less than 17 minutes without writing a single wordCreate a newsletter in less than 17 minutes without writing a single word
Create a newsletter in less than 17 minutes without writing a single wordNik Cree
 
Building a Simple Project Plan for WordPress Projects
Building a Simple Project Plan for WordPress ProjectsBuilding a Simple Project Plan for WordPress Projects
Building a Simple Project Plan for WordPress ProjectsLucas Lima
 
Organizing Your First Website Usability Test - WordCamp Boston 2016
Organizing Your First Website Usability Test - WordCamp Boston 2016Organizing Your First Website Usability Test - WordCamp Boston 2016
Organizing Your First Website Usability Test - WordCamp Boston 2016Anthony D. Paul
 
Passwords, Attakcks, and Security, oh my!
Passwords, Attakcks, and Security, oh my!Passwords, Attakcks, and Security, oh my!
Passwords, Attakcks, and Security, oh my!Michele Butcher
 

En vedette (20)

Core plugins - WordCamp UK 2010
Core plugins  - WordCamp UK 2010Core plugins  - WordCamp UK 2010
Core plugins - WordCamp UK 2010
 
State of the Word 2016
State of the Word 2016State of the Word 2016
State of the Word 2016
 
Design in Tech Report 2017
Design in Tech Report 2017Design in Tech Report 2017
Design in Tech Report 2017
 
Wordcamp 2010 I'm A Scientist Get me Out of Here - Mike Little
Wordcamp 2010 I'm A Scientist Get me Out of Here - Mike LittleWordcamp 2010 I'm A Scientist Get me Out of Here - Mike Little
Wordcamp 2010 I'm A Scientist Get me Out of Here - Mike Little
 
WordPress as a Service
WordPress as a ServiceWordPress as a Service
WordPress as a Service
 
Empowering Your Clients and Be an Advocate for Yourself
Empowering Your Clients and Be an Advocate for YourselfEmpowering Your Clients and Be an Advocate for Yourself
Empowering Your Clients and Be an Advocate for Yourself
 
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
 
Comunidade. Abuse e use dela com moderação e inteligência.
Comunidade. Abuse e use dela com moderação e inteligência.Comunidade. Abuse e use dela com moderação e inteligência.
Comunidade. Abuse e use dela com moderação e inteligência.
 
Sweet Child O' Themes
Sweet Child O' ThemesSweet Child O' Themes
Sweet Child O' Themes
 
Do marketplace ao WordPress - WordCamp BH 2015
Do marketplace ao WordPress -  WordCamp BH 2015Do marketplace ao WordPress -  WordCamp BH 2015
Do marketplace ao WordPress - WordCamp BH 2015
 
Método The bridge
Método The bridgeMétodo The bridge
Método The bridge
 
Debugging WordPress Core and Plugins!
Debugging WordPress Core and Plugins!Debugging WordPress Core and Plugins!
Debugging WordPress Core and Plugins!
 
Never fear, the customizer is here!
Never fear, the customizer is here!Never fear, the customizer is here!
Never fear, the customizer is here!
 
Getting to Know Underscores
Getting to Know Underscores Getting to Know Underscores
Getting to Know Underscores
 
Teresa Lane - Content Modeling - WordCamp St. Louis 2016
Teresa Lane - Content Modeling - WordCamp St. Louis 2016Teresa Lane - Content Modeling - WordCamp St. Louis 2016
Teresa Lane - Content Modeling - WordCamp St. Louis 2016
 
Create a newsletter in less than 17 minutes without writing a single word
Create a newsletter in less than 17 minutes without writing a single wordCreate a newsletter in less than 17 minutes without writing a single word
Create a newsletter in less than 17 minutes without writing a single word
 
Building a Simple Project Plan for WordPress Projects
Building a Simple Project Plan for WordPress ProjectsBuilding a Simple Project Plan for WordPress Projects
Building a Simple Project Plan for WordPress Projects
 
Organizing Your First Website Usability Test - WordCamp Boston 2016
Organizing Your First Website Usability Test - WordCamp Boston 2016Organizing Your First Website Usability Test - WordCamp Boston 2016
Organizing Your First Website Usability Test - WordCamp Boston 2016
 
Passwords, Attakcks, and Security, oh my!
Passwords, Attakcks, and Security, oh my!Passwords, Attakcks, and Security, oh my!
Passwords, Attakcks, and Security, oh my!
 
Teste A/B
Teste A/BTeste A/B
Teste A/B
 

Similaire à WordPress APIs

Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST APICaldera Labs
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPressTaylor Lovett
 
Webservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTPradeep Kumar
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP TutorialLorna Mitchell
 
Website designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentWebsite designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentCss Founder
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Designing a RESTful web service
Designing a RESTful web serviceDesigning a RESTful web service
Designing a RESTful web serviceFilip Blondeel
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009Jason Davies
 
PHP: The Beginning and the Zend
PHP: The Beginning and the ZendPHP: The Beginning and the Zend
PHP: The Beginning and the Zenddoublecompile
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxMichael Hackstein
 
Webservices Workshop - september 2014
Webservices Workshop -  september 2014Webservices Workshop -  september 2014
Webservices Workshop - september 2014clairvoyantllc
 
The never-ending REST API design debate
The never-ending REST API design debateThe never-ending REST API design debate
The never-ending REST API design debateRestlet
 

Similaire à WordPress APIs (20)

Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
 
Webservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and REST
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP Tutorial
 
Website designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentWebsite designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopment
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
&lt;?php + WordPress
&lt;?php + WordPress&lt;?php + WordPress
&lt;?php + WordPress
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Web api
Web apiWeb api
Web api
 
Designing a RESTful web service
Designing a RESTful web serviceDesigning a RESTful web service
Designing a RESTful web service
 
Web Services
Web ServicesWeb Services
Web Services
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009
 
PHP: The Beginning and the Zend
PHP: The Beginning and the ZendPHP: The Beginning and the Zend
PHP: The Beginning and the Zend
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
 
Webservices Workshop - september 2014
Webservices Workshop -  september 2014Webservices Workshop -  september 2014
Webservices Workshop - september 2014
 
The never-ending REST API design debate
The never-ending REST API design debateThe never-ending REST API design debate
The never-ending REST API design debate
 

Dernier

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Dernier (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

WordPress APIs

  • 1. WordPress APIs Feeds, XML-RPC, APP, and “REST” WordCamp OC - 2012/06/02 - Mike Adams
  • 2. Hi • Mike Adams = mdawaffe • Automattic/WordPress.com: ~6 years • WordPress developer: ~8 years • Team Social Lead
  • 3. Hi • Mike Adams = mdawaffe • Automattic/WordPress.com: ~6 years • WordPress developer: ~8 years • Team Social Lead Links/Examples: wp.me/p1s-3Z pee one ess dash three ZEE
  • 4. WordPress Data over HTTP • Feeds • XML-RPC • Atom Publishing Protocol • “REST”
  • 5. Evaluating • Provides useful data/ways to manipulate • Is easy to work with in any language • Well documented • Grokkable (human readable) • Command line is king
  • 6. Feeds • RSS v. Atom: essentially the same • Historically, RSS has gotten more love
  • 7. Feeds: Features • Get • Posts, Pages • Comments • Can use normal WordPress query args author_name=mdawaffe, search=wordpress, category_name=goats, page=2, ...
  • 8. Feeds: Tools • Command Line: curl • PHP: SimplePie http://simplepie.org/ • WordPress: fetch_feed() Simple wrapper for SimplePie • JS: It’s just XML? DOM, jQuery, ...
  • 9. Feeds: Examples • Via JS, get most recent post titles: jsfiddle.net/mdawaffe/ZQn5c/ • Via CLI, get URL of most recent post: curl example.com/feed/ | perl -pe 'BEGIN{$/=undef} s/.*?<item>.*?<link>(.*?)<.* /$1/s' Not really CLI if you resort to Perl :)
  • 10. Feeds: Examples • Count posts by Marla that contain the string “movie”. curl example.com/feed/ ?author_name=marla &search=movie | grep '<item>' | wc -l Nope: Won’t work
  • 11. Feeds: Caveats • Not always a perfect representation of for-display content • Never a good representation of for-edit content • Pagination • Plugins that add structured data to feeds may only touch RSS (not Atom)
  • 12. Feeds: Evaluation • Data: Posts, Comments Only. Read Only • Easy: Meh - Libraries • Docs: Lots of specs • Grok: Mostly • CLI: Not so easy
  • 13. Feeds: Conclusion • Quick way of reading basic data, but caveats • Longstanding, standard formats • Parsers available in every language • For WordPress, RSS > Atom
  • 14. XML-RPC • Remote Procedure Call = Function based • Developed by Dave Winer in 1999 • xmlrpc.scripting.com/spec.html
  • 15. XML-RPC: Request POST /xmlrpc.php HTTP/1.1 HOST: example.com Content-Type: text/xml Content-Length: 311 <?xml version="1.0"?> <methodCall> <methodName>wp.getPosts</methodName> <params> <param> <value> <array> <data> <value><int>0</int></value> <value><string>username</string></value> <value><string>password</string></value> </data> </array> </value> </param> </params> </methodCall>
  • 16. XML-RPC: Response HTTP/1.1 200 OK Content-Type: text/xml Content-Length: 27000 <?xml version="1.0"?> <methodResponse> <params> <param> <value> <array> <data> <value> <struct> <member><name>post_id</name><value><string>26</ string></value></member> <member><name>post_title</name><value><string>Space Monkey!</string></value></member> ... </struct> </value> <value> ...
  • 17. XML-RPC: WordPress • WordPress offers considerable functionality: Read and Write • Requires Authentication • Supported on all WordPress sites (Opt-in for non-WordPress.com sites) • Poorly Documented • Highly Extensible (via Plugin)
  • 18. XML-RPC: Features • Get/Create/Edit/Delete • Posts, Pages • Comments • Terms, Taxonomies • Options • Media Uploads
  • 19. XML-RPC: Auth • All (most) XML-RPC calls require authentication • WordPress.ORG • Username/Password • Extensible via Plugin
  • 20. XML-RPC: Auth • All (most) XML-RPC calls require authentication • WordPress.COM • Username/Password • OAuth2
  • 21. XML-RPC: Docs • XML-RPC is just a communication spec • Standard sets of Remote Procedures: Blogger, MoveableType, MetaWeblog, ... • WordPress supports them all! • codex.wordpress.org/XML-RPC_Support • wp-includes/class-wp-xmlrpc-server.php
  • 22. XML-RPC: Extensible • New Remote Procedures can be added with the xmlrpc_methods filter • Hooked function: • accepts array of arguments • returns most anything • XML parsing/serializing done by WordPress
  • 23. XML-RPC: Tools • Command Line: Hard • PHP: xmlrpc_encode_request() • WordPress: WP_HTTP_IXR_Client • JS: Mimic mimic-xmlrpc.sourceforge.net
  • 24. XML-RPC: Example $x = new WP_HTTP_IXR_Client($URL); $x->query( ‘wp.newPage’, array( 0, ‘user’, ‘password’, array( ‘title’ => ‘WordCamp’, ‘description’ => ‘OC, Baby!’ ), 1, ));
  • 25. XML-RPC: Caveats • Never a true representation of for-display content • Usually a true representation of for-edit content • Pagination impossible (until 3.4)
  • 26. XML-RPC: Evaluation • Data: Lots of functionality • Easy: Meh - Libraries • Docs: No • Grok: No • CLI: No
  • 27. XML-RPC: Conclusion • Pros • WordPress offers lots of functionality • Easy to extend • Cons • Caveats • Verbose XML • Poorly Documented
  • 28. APP • Atom Publishing Protocol • RESTful - object based • Posts are represented as Atom Feed entries • tools.ietf.org/html/rfc5023
  • 29. APP: WordPress • WordPress offers limited functionality • Requires Authentication • Supported on all WordPress sites (Opt-in for non-WordPress.com sites) • Poorly Documented • Harder to extend than XML-RPC
  • 30. APP: Features • Get/Create/Edit/Delete • Posts, Pages • Media Uploads
  • 31. APP: Auth • All APP calls require authentication • BASIC (Username/Password) • Extensible via Plugin
  • 34. APP: Evaluation • Data: Posts only • Easy: Not really. At least it’s XML. • Docs: No • Grok: Looks like a feed • CLI: No
  • 35. APP: Conclusion • Pro: Aesthetically cool • Cons • Not very well supported in WordPress • Hard to extend • Poorly documented • Don’t bother unless you are heavily invested in APP elsewhere already
  • 36. “REST”ful JSON • WordPress.COM has launched a new RESTful JSON API • Soon in Jetpack • Will likely be in core (3.6?)
  • 37. “REST”ful JSON • Fairly full featured • Public data does not require authentication • Private data requires OAuth2 • True representation of both for-display, and for-edit content • Well documented
  • 38. JSON: Features • Get/Create/Edit/Delete • Posts, Pages • Comments • Terms, Taxonomies • Media Uploads
  • 39. JSON: “REST” https://public-api.wordpress.com/rest/v1/sites/$site • Read: GET /posts/$post_id • Create: POST /posts/new • Update: POST /posts/$post_id • Delete: POST /posts/$post_id/delete POST requests can be JSON or form encoded
  • 40. JSON: Docs • Dynamically generated: always up to date • developer.wordpress.com/docs/api/ • Append “/help” to any API URL • API Console: AMAZING! developer.wordpress.com/docs/api/console/
  • 41. JSON: Tools • Command Line: curl • PHP: file_get_contents() • WordPress: wp_remote_request() • JS:Yes • Any language that can make remote HTTP requests and understand JSON(P)
  • 42. JSON: Examples • Get most recent post public-api.wordpress.com/rest/v1/sites/ en.blog.wordpress.com/posts/?number=1 jsfiddle.net/mdawaffe/hLWdH/ • Get a post’s likes public-api.wordpress.com/rest/v1/sites/ en.blog.wordpress.com/posts/11235/likes/ jsfiddle.net/mdawaffe/QgPqV/
  • 43. JSON: Examples • Create a Post curl --data 'title=WCOC' --data 'content=Rocks' -H 'Authorization: BEARER *SECRET*' https://public- api.wordpress.com/rest/v1/ sites/mdawaffe.wordpress.com/ posts/new
  • 44. JSON: Evaluation • Data: Not as fully featured as XML-RPC • Easy:Yes • Docs:Yes! • Grok:Yes • CLI:Yes!
  • 45. JSON: Conclusion • Pros • Easiest to use • Built in up-to-date documentation • True representation of for-display and for-edit content • Con: • Not as full featured as XML-RPC (yet!)
  • 46. Bye • Mike Adams = mdawaffe
  • 47. Bye • Mike Adams = mdawaffe • Thanks!

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n