Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
An introduction to the WordPress REST API
Search
Jack Lenox
November 19, 2016
Technology
1
210
An introduction to the WordPress REST API
Presented at WordCamp Athens 2016.
Created using Marp:
https://yhatt.github.io/marp/
Jack Lenox
November 19, 2016
Tweet
Share
More Decks by Jack Lenox
See All by Jack Lenox
How better performing websites can help save the planet
jacklenox
3
780
How better performing websites can help save the planet
jacklenox
0
1.5k
What WordPress developers can do about climate change
jacklenox
0
180
An Introduction to Object-Oriented Programming, Design Patterns, and Test-Driven Development
jacklenox
3
450
Building Websites with the REST API
jacklenox
0
260
There and Back Again: A Developer's Tale
jacklenox
3
1.8k
Writing PHP with React
jacklenox
0
380
Theming, React and the REST API
jacklenox
0
500
Building themes with the WP REST API
jacklenox
1
720
Other Decks in Technology
See All in Technology
DynamoDB でスロットリングが発生したとき_大盛りver/when_throttling_occurs_in_dynamodb_long
emiki
1
450
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
220
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.6k
SDNという名のデータプレーンプログラミングの歴史
ebiken
PRO
2
130
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
160
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
7
690
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
130
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
110
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
640
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
Terraform Stacks入門 #HashiTalks
msato
0
360
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
190
Featured
See All Featured
Code Review Best Practice
trishagee
64
17k
The Language of Interfaces
destraynor
154
24k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Six Lessons from altMBA
skipperchong
27
3.5k
Navigating Team Friction
lara
183
14k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Typedesign – Prime Four
hannesfritz
40
2.4k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Facilitating Awesome Meetings
lara
50
6.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Transcript
An introduc on to the WordPress REST API Jack Lenox
(@jacklenox) WordCamp Athens 2016
I Greece!
1. The case for a WordPress REST API
What is a REST API?
It stands for REpresenta onal State Transfer Applica on Programming
Interface
Centred around verbs GET POST UPDATE PUT DELETE etc. Different
ways to interact with your data
Usually responds in XML or JSON format XML (Extensible Markup
Language) HTML RSS JSON (JavaScript Object Notation)
Why does WordPress need one?
None
MoMA in New York (c. 2009) Their developers wanted to
use: WordPress as the CMS Ruby to build the front-end
Why? I don't know... but they did
None
WordPress.com API Released in 2012 Available to self-hosted sites via
Jetpack Powerful and road-tested Not extensible (unless you work at Automa c!)
None
REST API use cases Non-PHP implementations Mobile devices But most
recently...
JavaScript OMGBBQ!
None
Internet of things
So, what is the WordPress REST API?
None
None
Merge meline WordPress 4.4 (8 December 2015) Infrastructure merged No
endpoints WordPress 4.7 (due 6 December 2016) Endpoints merged!
2. How the WordPress REST API works (aka, what the
heck is an endpoint?)
End‐what? REST APIs interprets a URL, and return a response
Not wildly different to RSS Sample request to fetch some posts: wc-athens.dev/wp-json/wp/v2/posts
[ { "id": 1, "date": "2016-11-18T14:08:53", "date_gmt": "2016-11-18T14:08:53", "modified": "2016-11-18T14:08:53",
"modified_gmt": "2016-11-18T14:08:53", "slug": "hello-world", "type": "post", "link": "http://wp-rest-api-demo.dev/2016/11/18/hello-wor "title": { "rendered": "Hello world!" }, "content": { "rendered": "<p>Welcome to WordPress. This is your fi "protected": false } } ]
More endpoints... Single post: wc-athens.dev/wp-json/wp/v2/posts/1 All pages: wc-athens.dev/wp-json/wp/v2/pages All users:
wc-athens.dev/wp-json/wp/v2/users All categories: wc-athens.dev/wp-json/wp/v2/categories
Moar verbs! By default, our calls to the REST API
are GET requests. But we can do a lot more: POST PUT UPDATE DELETE
Authen ca on!
A few ways to authen cate Basic Authen ca on
Quick and dirty Cookie Authen ca on Good, especially for themes and plugins OAuth 1.0 A bit complicated, but versatile OAuth 2 Less complicated than OAuth 1, but requires HTTPS
Brokered Authen ca on The broker apps.wp-api.org Otherwise, it's OAuth
1.0
Modifying endpoints
3. Uses for the WordPress REST API
Custom wp‐admin interfaces Calypso developer.wordpress.com/calypso/ Happytables www.happytables.com
Mobile applica ons WordPress apps for iOS and Android apps.wordpress.com/mobile/
Vienna github.com/joehoyle/vienna
Themes Picard github.com/automattic/picard/ Anadama github.com/ryelle/anadama-react/ Foxhound github.com/ryelle/foxhound/
Plugins WooCommerce github.com/woocommerce/woocommerce EDD github.com/easydigitaldownloads/Easy-Digital- Downloads Syndication?
Enterprise Quartz qz.com Facebook facebookbrand.com Google IO (not WordPress, but...)
events.google.com/io2016/
Very exci ng mes ahead!
Further reading, and any ques ons? The WordPress REST API
docs v2.wp-api.org WordPress TV wordpress.tv (search "REST API") javascriptforwp.com
Ευχαριστώ πολύ! @jacklenox We're hiring! automa c.com/work‐with‐us/