Drupal as a Web Services Platform
Upcoming SlideShare
Loading in...5
×
 

Drupal as a Web Services Platform

on

  • 3,310 views

A high level overview of what it means to provide web services, what REST is, why meaningful URLs are important, and how to implement REST services in Drupal.

A high level overview of what it means to provide web services, what REST is, why meaningful URLs are important, and how to implement REST services in Drupal.

Statistics

Views

Total Views
3,310
Views on SlideShare
3,308
Embed Views
2

Actions

Likes
6
Downloads
65
Comments
0

2 Embeds 2

http://a0.twimg.com 1
http://paper.li 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • Introductions, where I work, pimp the book, talk about the initiative (configuration management and content deployment.) Talk about work with Deploy module and how that got me interested in the web services arena.\n
  • So what do we mean by Web Services Plaform? It sounds like a lot of marketing buzzword hoohah to me.\n
  • In the modern age, a website isn’t just for browsers. In fact, focusing on a web-only view of the world is very limiting because there are many other ways in which the data in your CMS can be used. and lets not forget the plethora of social media systems that appear and disappear on a seemingly daily basis - each with their own APIs and ways of getting data in and out. You want your system to be able to handle these needs without having to remake your data for each one. Web services are the way to do this.\n
  • In the modern age, a website isn’t just for browsers. In fact, focusing on a web-only view of the world is very limiting because there are many other ways in which the data in your CMS can be used. and lets not forget the plethora of social media systems that appear and disappear on a seemingly daily basis - each with their own APIs and ways of getting data in and out. You want your system to be able to handle these needs without having to remake your data for each one. Web services are the way to do this.\n
  • In the modern age, a website isn’t just for browsers. In fact, focusing on a web-only view of the world is very limiting because there are many other ways in which the data in your CMS can be used. and lets not forget the plethora of social media systems that appear and disappear on a seemingly daily basis - each with their own APIs and ways of getting data in and out. You want your system to be able to handle these needs without having to remake your data for each one. Web services are the way to do this.\n
  • In the modern age, a website isn’t just for browsers. In fact, focusing on a web-only view of the world is very limiting because there are many other ways in which the data in your CMS can be used. and lets not forget the plethora of social media systems that appear and disappear on a seemingly daily basis - each with their own APIs and ways of getting data in and out. You want your system to be able to handle these needs without having to remake your data for each one. Web services are the way to do this.\n
  • In the modern age, a website isn’t just for browsers. In fact, focusing on a web-only view of the world is very limiting because there are many other ways in which the data in your CMS can be used. and lets not forget the plethora of social media systems that appear and disappear on a seemingly daily basis - each with their own APIs and ways of getting data in and out. You want your system to be able to handle these needs without having to remake your data for each one. Web services are the way to do this.\n
  • Web services provide a standardized and documented way for other applications retrieve and save data into your CMS that is machine-readable - code can read it and rely on it being a certain way. The collection of all the services you provide is called an API - Application Programming Interface. \n
  • Traditionally, these have tended towards complex XML standards that, while highly detailed, were difficult to parse and read. These systems were designed very procedurally, just like code - you defined a function that took very specific inputs, and you returned very specific data. Most of all it doesn’t work how the web works. This made sense for engineers who are used to this kind of interface, but the learning curve was steep and it wasn’t very easy to read responses on the face of it. This, for example, is an example of implementing Hello World in SOAP. Indicate where the actual data is. \n
  • In the modern age, web services are turning more and more towards REST which I could go into a lot of detail about, but it is really just a fancy way of saying ‘Put some very simple and easy to read data at a URL.’ This URL should be unique and it should identify the data being retrieved, and ideally it should be meaningful when you read it. This is an example of how you might write the Hello World app as a REST web service. Look how much simpler this is. \n
  • Here is a slightly more concrete example. This is a call to the url user/heyrocker that retrieves some information from Drupal about... the user named heyrocker. This is on the face of it understandable and you can largely figure out what you are looking at. There’s my user id, name, email, date my account was created, you can even nest more detailed information like what roles I am assigned to. This is really great, its simple to use and most of all it works how the web works, its not hacking a solution on around existing technologies.\n
  • Now in the next example you can see we are calling user/heyrocker/friends.json - we are asking for the friends of the user named heyrocker. URLs can be associated with not just a single piece of data but a collection of data, and you can see here how we are starting to craft the URLs to represent a hierarchy or set of relationships between the data being returned. This is a common concept in the design of REST APIs. \nThere is a lot of theory behind structured REST designs, but once you start paying attention you will start noticing these relationships in the URL design of popular websites, especially forward thinking modern sites like Flickr and Twitter. One reason this is nice is because your URLs become predictable, your users can easily get to the data they want by knowing how your URLs are designed. Flickr is my favorite example of this.\n
  • Here’s the flickr page that is the index for all my photos. Note the url.\n
  • Here is a page showing all the photos tagged ‘ozu’. Now a lot of what you’ll find here are photos related to the Japanese film director Yasujiro Ozu, like that book at the top left. However Ozu also happens to be the name of my cat, and while he is named after the director that’s not necessarily what I’m looking for.\n
  • However by appending tags/ozu onto my index page, it filters the content down to photos that are mine AND tagged Ozu, and now you have lots of cute photos of my cat. It makes so much sense, and it makes finding stuff on your site so much easier.\n
  • For instance, Jeff Eaton has the cutest cat Maddie and I often use her photo in presentations because, I mean, who doesn’t like a gorgeous cat right? I could bookmark this URL so I can access it again and again, but I don’t have to, I know what it is because Flickr uses a predictable URL architecture. I instantly have pretty much their entire database at my fingertips. Not only is it good for users, but it also vastly improves SEO because Google can do the same thing and Google loves predictable data. URL design is information architecture at its most base level, and it is also key to designing useful web services. I’m getting a little off track so lets say REST is good. It is just as useful as the old methods because it is much simpler and it works how the web works. \n
  • What this means to you is that you want a system that can manage your data in a modern format that application programmers are used to dealing with so that you can integrate with all these systems that you need to. Guess what? Drupal is an system for doing this! While there are several ways to go about implementing this, I’m going to talk about a module called Services which was created for exactly this use case. (I also maintain it along with a dedicated group of highly talented and awesome developers.)\n
  • Services provides a standard and extensible way to provide the data on your Drupal site through a web services interface. These interfaces are pluggable, you can choose the one you want to use, but the default it ships with in the current version is REST. Out of the box, Services provides access to core Drupal objects like nodes, users, and taxonomy, and you can write your own resources to expose custom functionality that is specific to your business. Finally, Services also provides a pluggable authentication mechanism. By default it uses standard Drupal logins but it can also use custom token systems or other mechanisms like oAuth. Used on 12,000+ sites including FCC, Warner Brothers, IKEA. Go-to answer for mobile apps. \n
  • \n
  • Next you enable the resources you want. This is the standard set of resources that come with Services and provide functionality for Drupal core. Note that on the left you can alias where any of these resources live. For instance, you can change all the node resources to live under content instead to make your urls more readable and friendly.\n
  • Clicking on one of the areas opens a list of the individual functions that are available. This is the list of all the functions available for comments. Note that in addition to the usual CRUD functions, there are also custom functions to count the number of comments on a node, or count the number of new comments since a given timestamp. You can enable none or all of these in each given area.\n
  • Services also features pluggable formatters for responses and requests, so when the wacky new hotness comes along you can easily install or write it. By default it includes all sorts of stuff as well.\n
  • At this point, you can access the URLs and start pulling and submitting data. Now, there is still some understanding to be had around this, especially when it comes to formatting data for submission to Drupal, but on the Drupal side that is really all you have to do.\n
  • So lets do a demo. So when I was thinking about this I knew I wanted to make a Drupal site and an iPhone app and release the code for people to take away with them. I was trying to come up with an idea and I was talking to James Walker, a former Lullabot who often did demos for module development. He told me about the pants module. \n\nHigh points: Tell story about its conceptualization. Login and authentication. Searching for and adding friends. Note lack of privacy controls “Information (about your pants) wants to be free!”\n
  • This module was used to track whether or not the user in question was in fact wearing pants at any given time. It was a really great demo because while it was silly it also surprisingly lent itself to demonstrating a lot of core Drupal concepts really well. So after talking to James I thought it was time to bring the pants module into the modern age, and since there is a long history of fantasy/parody sites in the Drupal community I came up with the idea for...\n
  • Pantsquare! The newest social networking phenomenon! Use your mobile device to check in with whether or not you are wearing pants! Connect with your friends and see whether or not they are wearing pants either! Share pants-related information! Pantsquare is an app built in Titanium for iPhone and Android by myself and my co-worker BJ Wilson. It demonstrates a lot of useful Services functionality like managing authentication, writing your own services, and submitting data. \n
  • Versioning your APIs\nThink about performance impact (in many ways same as other requests because of boostrap)\nWhat dev environment to use?\nPoint people to Sumit’s talk later where he will get more dirty into the nerd stuff\n
  • Versioning your APIs\nThink about performance impact (in many ways same as other requests because of boostrap)\nWhat dev environment to use?\nPoint people to Sumit’s talk later where he will get more dirty into the nerd stuff\n
  • A lot of people have a tendency to ignore web services traffic but this can be a mistake. As time goes on, mobile and other traffic is going to take up a greater and greater percentage of your site traffic, and with Drupal each of these requests carries the same overhead in memory and other resources as any other request (due to bootstrap architecture, being fixed in Drupal 8)\n
  • This is a similar point to the last slide. Services exposes the same data to users that Drupal does, but if you implement your own services you have to make sure and implement that yourself. We didn’t do this on Pantsquare - everyone can see the status of everyone’s pants. Because of course information about pants wants to be free. (no actually we just ran out of time.) However this may not be your use case. Test thoroughly because these kinds of problems are the ones that will really bite you on the Twittersphere.\n
  • A lot of the time you will get into long discussions about what to develop apps in or pros and cons of technical decisions that in the end don’t really matter all that much. Use what you have competence in, focus on UX and Features and stuff.\n
  • There’s a post running all over the internet right now from a Google and former Amazon engineer that talks about how the one thing Amazon has done right is they built an API for users but they also use it themselves for EVERYTHING. There are no personal internal-only services, there is no direct linking between teams, there is only the APIs that everyone else has. They eat their own dogfood. This is huge because it forces you to build the best thing you can because you need it as much as anyone else does. This is what building a platform is all about. Start with a platform and use it for everything.\n
  • \n
  • \n

Drupal as a Web Services Platform Drupal as a Web Services Platform Presentation Transcript

  • Drupal as a WebServices Platform Do It With Drupal 2011 Greg Dunlap - @heyrocker B.J. Wilson -- @
  • Who Am I?
  • What do we mean by Web Services Platform?
  • Mobile app
  • LegacyMobile app integration
  • LegacyMobile app integration Partners
  • LegacyMobile app integration Partners SSO/LDAP/etc
  • LegacyMobile app integration Partners SSO/LDAP/etc
  • What are webservices exactly?
  • RequestResponse http://oreilly.com/catalog/progwebsoap/chapter/ch03.html
  • Request http://example.com/helloResponse {"response":"OHAI!"}
  • Request http://example.com/user/heyrockerResponse { uid: "2" name: "heyrocker" mail: "heyrocker@example.com" created: "1315079427" login: "0" status: "1" timezone: "Europe/Stockholm" language: "" picture: "4" roles: { 2: "authenticated user" 3: "administrator" } }
  • Request http://example.com/user/heyrockerResponse { uid: "4" name: "pontus" image: "http://example.com/sites/default/files/pontus-small.png" } { uid: "5" name: "bahador" image: "http://example.com/sites/default/files/bahador-small.png" } { uid: "6" name: "simon" image: "" }
  • http://flickr.com/photos/heyrocker
  • http://flickr.com/tags/ozu
  • http://flickr.com/photos/heyrocker/tags/ozu
  • http://flickr.com/photos/jeffeaton/tags/maddie
  • OK what does this mean to me?
  • http://drupal.org/project/services
  • 1) Add a new endpoint
  • 2) Enable resources
  • 2) Enable resources
  • 3) Configure formatters
  • That’s It!
  • Let’s see it in action!
  • http://pantsquare.me
  • Tips and tricks
  • Version Your APIshttp://pantsquare.me/api/v1/node/23
  • Considerperformance
  • Check permissions carefully
  • Don’t sweat dev environments
  • Don’t build a publicAPI, just build an API
  • Additional ResourcesServiceshttp://drupal.org/node/736522http://groups.drupal.org/services#drupal-services on freenode.net IRCFrameworkshttps://github.com/workhabitinc/drupal-ios-sdkhttps://github.com/skyred/DrupalCloudCode (Coming Soon)https://github.com/heyrocker/Pantsquare-Apphttps://github.com/heyrocker/PantsquareSumit Kataria’s talk after lunch
  • Q/A