Khanh Hoang - Kenn
Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.
As we all are working very hard for upcoming major release I am feeling excited to write this. This blog is all about REST Export feature of Drupal 8’ view. Let me first brief you about what is the REST api and than I will explain you how REST Export is important for building custom REST api for your Drupal 8.
REST (Representational State Transfer) is a web service architecture to expose your resources to outer world. It follows http architecture to expose the resources of your web site i.e you have GET, POST, PATCH,DELETE etc methods to manipulate resources with out web interface. In context to Drupal , a node will have GET method that will require node id and it will return you details related to that node in XML, JSON or HAL + JSON format. If you have ever used REST api for some famous web services like twitter, facebook then you will find those API very well defined for example GET on /status will give you current status details and GET on /status/comments will give you comments posted on your current status. In context to Drupal we should get node details with GET on /node/{id} and comments on particular node with GET on /node/{id}/comments. In Drupal 8 we have first REST endpoint but we don’t have second. Drupal has opt for different approach. In Drupal you can use contextual filters on view to filter content as per your parameters passed in URL . The same concept we can applies to REST Export . We can attach a REST Export to a view that only show comments with contextual filter with nodeID as parameter. So the rest export will return XML or JSON for comments related to particular node.
Here is a screenshot for it.
We can use REST Export with taxonomy_terms for particular vocabulary as parameter. This concept will make Drupal 8 REST api robust and it also provides good example where view modules and REST module works to gather to provide developer flexibility to develop custom REST api for their Drupal site.