sunshine php

Download SunShine PHP

Post on 12-Apr-2017

132 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

  • T H E W O R D P R E S S R E S T A P I

    D A V I D B I S S E T @dimensionmedia

  • W H AT I S A R E S T A P I ?

  • REpresentational State Transfer Application Programing Interface

  • W H A T I S A R E S T A P I ?

    Separation Between Client and Server Stateless: No State, You Should Get Same

    Data From Same Requests Cacheable Layerable: Load-Balancing, etc. Uniform: REST APIs typically tell you how to

    access the data. Flexible: Doesnt Matter Where Server/Client

    Area, Or What They Are Simple: Uses Standard/Established Methods

  • C R U D A N D H T T P M E T H O D S

    CREATE -> POST READ -> GET UPDATE -> PUT DELETE -> DELETE

  • W H AT I S T H E W P R E S T A P I ?

  • W O R D P R E S S + R E S T A P I =

    A W E S O M E S A U C E

  • REQU IREMENTS

    WordPress 4.4 WP REST API Plugin 2.0

  • L E T S D I V E I N !

  • P O S T M A Nhttps://www.getpostman.com/

    Allows us to build and send requests to our API and also

    process and handle responses. A really great tool for working with any type of REST API, not just the

    WordPress API.

    https://www.getpostman.com/

  • http://local.wordpress.dev/wp-json

    http://local.wordpress.dev/wp-json

  • davidbisset.com/wp-json/wp/v2/posts/

    http://davidbisset.com/wp-json/wp/v2/posts/

  • davidbisset.com/wp-json/wp/v2/comments/

    http://davidbisset.com/wp-json/wp/v2/comments/

  • davidbisset.com/wp-json/wp/v2/media/davidbisset.com/wp-json/wp/v2/media/1792

    http://davidbisset.com/wp-json/wp/v2/media/http://davidbisset.com/wp-json/wp/v2/media/1792

  • U S I N G C U R L & W P _ H T T P

  • curl http://local.wordpress.dev/wp-json/wp/v2/posts

    http://davidbisset.com/wp-json/wp/v2/comments/

  • $curl = curl_init();

    curl_setopt ($curl, CURLOPT_URL, "http://local.wordpress.dev/wp-json/wp/v2/posts");

    $json = curl_exec ($curl);

    curl_close ($curl);

    $data = json_decode($json);

    var_dump($data);

  • $json = wp_remote_get( 'http://local.wordpress.dev/wp-json/wp/v2/posts' );

    $return = json_decode( $json['body'] );

    var_dump($return);

  • W O R K I N G W I T H P O S T S

  • davidbisset.com/wp-json/wp/v2/posts/

    http://davidbisset.com/wp-json/wp/v2/posts/

  • davidbisset.com/wp-json/wp/v2/posts/1805

    http://davidbisset.com/wp-json/wp/v2/posts/1805

  • F I LT E R I N G P O S T S

  • /wp-json/wp/v2/posts/?filter[orderby]=rand

    http://davidbisset.com/wp-json/wp/v2/posts/

  • davidbisset.com/wp-json/wp/v2/posts/?filter[s]=dradcast

    http://davidbisset.com/wp-json/wp/v2/posts/?filter%5Bs%5D=dradcast

  • /wp-json/wp/v2/posts/?filter[posts_per_page]=1&filter[paged]=1&filter[s]=dradcast

    http:///wp-json/wp/v2/posts/?filter%5Bposts_per_page%5D=1&filter%5Bpaged%5D=1&filter%5Bs%5D=dradcast

  • PA G E S

  • /wp-json/wp/v2/pages/

    http://davidbisset.com/wp-json/wp/v2/posts/?filter%5Bs%5D=dradcast

  • P O S T M E TA

  • P O S T M E TA ( F I LT E R I N G )

  • davidbisset.com/wp-json/wp/v2/posts/?filter[meta_key]=test_meta

    http://davidbisset.com/wp-json/wp/v2/posts/?filter%5Bmeta_key%5D=test_meta

  • A U T H E N T I C AT I O N

  • T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W :

    Basic Authentication via a plugin Cookie Authentication out of the box Oauth2 Authentication via a plugin (third party) Oauth1 Authentication via a plugin

  • T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W :

    Basic Authentication via a plugin Cookie Authentication out of the box Oauth2 Authentication via a plugin (third party) Oauth1 Authentication via a plugin

  • BAS IC -AUTHhttps://github.com/WP-API/Basic-Auth

    https://github.com/WP-API/Basic-Auth

  • TA D A ! B A S I C A U T H G E T S Y O U T H E S A M E A C C E S S / R O L E S A S Y O U R W P U S E R

  • F O R E X A M P L E , I F Y O U H A V E A D M I N A C C E S S Y O U C A N S E E A L L U S E R S

  • T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W :

    Basic Authentication via a plugin Cookie Authentication out of the box Oauth2 Authentication via a plugin (third party) Oauth1 Authentication via a plugin

  • T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W :

    Basic Authentication via a plugin Cookie Authentication out of the box Oauth2 Authentication via a plugin (third party) Oauth1 Authentication via a plugin

  • T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W :

    Basic Authentication via a plugin Cookie Authentication out of the box Oauth2 Authentication via a plugin (third party) Oauth1 Authentication via a plugin

  • D I G G I N G I N T O T H E A P I : C R E AT I N G A N E W P O S T

  • D I G G I N G I N T O T H E A P I : A D D N I N G & U P D AT I N G P O S T

    M E TA T O A P O S T

  • D I G G I N G I N T O T H E A P I : D E L E T I N G A P O S T

  • W H Y T H I S I S C O O L

    Reverse Mullet: Business in back, party in the front You dont have to write PHP (write what you want) WordPress Can Now Power Native Mobile

    Applications Desktop Applications Possible More engaging user experience Offline: Control over failed connections, etc.

  • T H E M E S W I T H T H E W O R D P R E S S R E S T A P I

  • B U I L D I N G A P L U G I N U S I N G W P - A P I A N D A J A X

  • W H AT W E A R E B U I L D I N G

  • T H I N K A B O U T T H E A P I R E Q U E S T U R L

  • New WordPress 4.4 Install Used FakerPress To Add Random Content/

    Categories Installed the WP REST API Plugin Using Popper As My Theme

    B U I L D T H E P L U G I N : S E T U P

  • B U I L D T H E P L U G I N : F I R S T S T E P S

  • B U I L D T H E P L U G I N : F I R S T S T E P S

  • B U I L D T H E P L U G I N : S E T U P F U N C T I O N S

  • S O O N 2 5 % O F T H E W E B

    W I L L H A V E A C C E S S T O T H E W O R D P R E S S R E S T A P I A N D W I L L B E U S E D F O R I N T E R E S T I N G T H I N G S

  • R E S O U R C E Shttp://wp-api.org/ Official Documentation

    http://wp-api.org/

  • WordCamp Miami 2016February 19-21 FIU College of Business

  • T H A N K Y O U

    D A V I D B I S S E T @dimensionmedia

  • david bissetD A V I D B I S S E T. C O M

    @ D I M E N S I O N M E D I A

    http://davidbisset.com