Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to REST API

Introduction to REST API

Prasath Nadarajah

April 05, 2016
Tweet

Other Decks in Technology

Transcript

  1. Whats is REST? • Representational State Transfer • Simpler and

    easy to implement. • Uniform interface / Decoupled architecture • Stateless • Cacheable • Client-server • Layered system
  2. HTTP verbs • POST - create something • GET -

    get something • PUT - update something • DELETE - delete something • PATCH - partial update • HEAD - retrieve header info • OPTIONS - list available actions • TRACE - Echo back
  3. HTTP status codes • 1xx - Informational • 2xx -

    Success • 3xx - Redirection • 4xx - Client error • 5xx - Server error
  4. Why REST API in WordPress? • More flexibility • Decouple

    Front End and CMS • Multiple frontends • Faster applications and interactive experiences
  5. State of REST API in WordPress • WordPress already had

    an XML-RPC based web service • First started as a Google Summer of Code project by Ryan McCue • Developed as a plugin now.. Currently in 2.0 beta 13 • Follow the updates and participate
  6. List of REST API Endpoints • Post • Post revisions

    • Pages • Media • Post types • Post statuses • Categories • Tags • Users • Comments • Taxonomies
  7. Adding a new endpoint <?php add_action( 'rest_api_init', function () {

    register_rest_route( 'myplugin/v1', '/author/(?P<id>\d+)', array( 'methods' => 'GET', 'callback' => 'my_awesome_func', ) ); } );
  8. GraphQL • A data query language • Developed by Facebook

    • Its a specification Task : Implementing a GraphQL server for WordPress