best practices for creating wp rest api by galkin nikita

11
Best Practices for creating WordPress REST API by Galkin Nikita WORDPRESS KITCHEN MEETUP SPRING 2016

Upload: wordcamp-kyiv

Post on 09-Jan-2017

145 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Best Practices for creating WP REST API by Galkin Nikita

Best Practices for creating WordPress

REST APIby Galkin Nikita

WORDPRESS KITCHEN MEETUP SPRING 2016

Page 2: Best Practices for creating WP REST API by Galkin Nikita

Useful links

http://v2.wp-api.orghttps://wordpress.org/plugins/rest-api/http://raml.orghttps://www.getpostman.comhttps://c9.iohttps://wp-rest-galk-in.c9users.iohttps://github.com/galk-in/

Page 3: Best Practices for creating WP REST API by Galkin Nikita

Default REST in Wordpress 4.4

Start endpoint http://example.com/wp-json/

Added oembed/1.0/ namespace

Off REST API

add_filter('rest_enabled', function() {return false;});

Page 4: Best Practices for creating WP REST API by Galkin Nikita

Standart REST API

{ "name": "Example WordPress Site", "namespaces": [ "wp/v2", "oembed/1.0/" ]}

Page 5: Best Practices for creating WP REST API by Galkin Nikita

Add route

add_action( 'rest_api_init', function () { register_rest_route( 'myplugin/v1', '/example/', array( 'methods' => 'GET', 'callback' => function($request) {

return "Hello world!";}, ) );} );

Page 6: Best Practices for creating WP REST API by Galkin Nikita

Namespace =<plugin|theme>/<version>

Page 7: Best Practices for creating WP REST API by Galkin Nikita

Routelast part of

endpoint

Page 8: Best Practices for creating WP REST API by Galkin Nikita

Arguments

methods

callback

permission_callback

argsdefault

required

sanitize_callback

validate_callback

Page 9: Best Practices for creating WP REST API by Galkin Nikita

Middleware

Page 10: Best Practices for creating WP REST API by Galkin Nikita

ETAG

Page 11: Best Practices for creating WP REST API by Galkin Nikita

RAML