SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

WordPress Customization and Security
WordPress Customization and SecurityWordPress Customization and Security
WordPress Customization and Security
Joe Casabona
 
SharePoint Development 101
SharePoint Development 101SharePoint Development 101
SharePoint Development 101
Greg Hurlman
 

Mais procurados (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
 

Destaque

Destaque (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
 

Semelhante a WordPress APIs

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 
Designing a RESTful web service
Designing a RESTful web serviceDesigning a RESTful web service
Designing a RESTful web service
Filip Blondeel
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
Michael Hackstein
 

Semelhante a 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
 

Último

Último (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

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!

Notas do Editor

  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