While cURL may not be the simplest way to interact with a REST API it is the most ubiquitous and the one that is most often referenced in documentation through the web. So to ensure that students have at least a baseline of understanding, and will know how to read the documentation in the future, in this lesson Joe takes a quick look at how to test our API with cURL by retrieving, and creating data.
Example Commands:
`curl http://localhost/demos/services-7x/docroot/api/v1/node/1`
`curl --data '{"title":"hello world!","type":"page"}' --header "Content-Type:application/json" http://localhost/demos/services-7x/docroot/api/v1/node`
Additional resources
Instead of using the CLI to test our API we can use the powerful Chrome REST Console plugin instead. This provides a nice GUI and makes it a little easier to both test and understand what is going on. In this lesson Joe looks at installing the plugin and making basic requests to our API using the REST Console interface.
Additional resources
The Chrome plugin demonstrated in this video is no longer available but there are many alternatives available. Use Postman or search for "REST client" to find tooling options.
In Drupal 8, the entire block system got an overhaul, and there are lots of goodies in there. I took a tour of the new system with a short video. Some of the biggest changes to see are that you can now use blocks more than once on your site, and there is a new Custom block library that lets you create block types, which are very much like content types for blocks. They let you add fields to blocks, and give you more fine-grained control over how those fields are displayed depending on the location. Check out the video to see some of this in action.
This week, we're introducing a new series for you module developers out there: Building Web Services with Drupal 7. Why? Because you asked for it.
Web services, APIs, and structured data are all the rage right now, and with good reason. As more and more internet enabled devices start wanting to make use of the data in our websites, we need to give them some way to interact with that data that isn't point and click in a browser. Enter the Drupal 7 services module.
In this series Joe Shindelar will walk through the services module and teach you how to create a RESTful web services API that exposes Drupal's internal data like nodes and users as JSON or XML. This paves the way for a huge variety of clients using a number of programming languages to access the data contained within your Drupal site, from native mobile applications and partner websites to internet enabled refrigerators.
The first few lessons in the series are focused more on theory. They explain the various terms that are used both in Drupal and the wider web development sphere to describe web services and all their components. Joe describes REST itself and explains why it's a good fit, and discusses Drupal 7's content model and the ways that it lends itself nicely to serializing data into various formats via the services module in order to be consumed in structured and meaningful ways.
Throughout the series we'll see a couple of examples of how to first enable Drupal to return requested data elements as JSON and then subsequently how to properly format an HTTP request to retrieve those elements. Joe will demonstrate making requests to the API via both cURL and the Chrome REST Console. This demonstration will help students to learn about both the Drupal configuration that is required and the way in which any third party applications can request data from Drupal via concrete examples.
With the basics of creating an endpoint and making simple requests out of the way, Joe will demonstrate how to enable authentication via the services module and then use both cURL and the REST Console to explain the authentication handshake: a somewhat complex exchange of a username and password for a session authentication token that takes place in HTTP requests and headers whenever you want to perform an action via the API that requires an authenticated user. This will enable to you create third party applications that can access Drupal as a specific user, allowing for greater personalization.
After that, Joe looks at ways to integrate the lists that site administrators create using the views module with services in order to output their contents as structured data, as well as ways to use views to create entirely new custom services resources, followed by an example of leveraging the power of views exposed filters via services.
Finally, for those scenarios where you simply can't point and click your way to an answer, Joe will teach you how to implement your own custom services resources for both saving and retrieving data from within Drupal, demonstrating the basic knowledge required to allow you to use services to solve all of your own custom API needs.
Things you'll be able to do after completion of this series:
- Understand the basic principles of both web services and RESTful APIs.
- Explain why Drupal is a good fit for web applications that want to allow third party clients to access their data.
- Create a RESTful web services API using the services module for Drupal 7.
- Retrieve data from your Drupal site in both JSON and XML format.
- Create new nodes in Drupal via web services.
- Make authenticated requests to Drupal via web serivces.
- Integrate the views module with services to retrieve views data in various formats.
- Write your own module providing custom services data and actions.
- Create meaningful documentation that will enable others to take advantage of your newly created service.
This series provides information about the services module for both intermediate and advanced Drupal users. Since this module makes use of basic Drupal site building skills and custom views, users should be familiar with those topics. Also, while not required, knowledge of running commands via the command line will be helpful. Finally, if you want to write your own custom services resources you'll need to understand basic module development.
Additional resources
This lesson covers what an API is and why you might want to build one. Joe also explains the basic concepts behind any API and provides real world examples of existing APIs that you're probably familiar with as well as use cases for when and why you might want to build your own.
In this lesson Joe shows you where to locate the services module and it's documentation. Then walks through installing the services module and confirming that it's working. Followed by a quick overview of the module's codebase and a general overview of what the services module provides.
Additional resources
The API that we're going to be building through this series is a REST based API so we need to understand the basic tenants of RESTful web services. In this lesson Joe gives a short presentation explaining the basic terminology, workflow, and tennants of REST based web services.
Additional resources
I'm sure you've heard by now that PHPtemplate is being replaced by Twig in Drupal 8. If you're a front end developer, you may be excited or afraid about how this will affect you. Let's take a look at the guiding principles behind the Twig initiative and where you can find documentation for theming in Drupal 8.
With the number of internet connected devices increasing rapidly it's important to make sure that your content, and your business, can be read and understood by machines. Creating an Application Programmer Interface, or API, which exposes your content in machine readable formats like JSON or XML is one of the best ways to accomplish this. Next week Joe Shindelar will be hosting a free webinar to show you how to build APIs on top of Drupal 7 with the Services module.
Drupalize.Me Podcast Episode 37
Blog postThis week's episode of our podcast, Bunny Ears Are Fuzzy, is a bit of a different than our regular podcast.
This week we are wrapping up our Working with Media Module in Drupal 7 series. We complete the site by getting our music views into place and adding YouTube video embeds.
This week, we'll tame images and audio files as we continue our Working with Media Module in Drupal 7 series with Addison Berry.
Exploring the New Drupal 8 Display Modes
Blog postDrupalize.Me Podcast Episode 36
Blog postIn our latest podcast episode we have two guests, Klaus Purer (klausi) and Lin Clark (linclark) joining Addi and Joe Fender to talk about the new REST module that has been added to Drupal 8 core.
Release Day: Creating Image Galleries
Blog postThis week we turn our attention back to the Working with Media Module in Drupal 7 series. We have a basic site in place, and now we need to add some features to make it rich with media. These three videos walk through the steps to create good-looking image galleries. They also show how we can work with third-party JavaScript libraries to enhance features on our site. Finally we add a listing page and front page block so users can find our new galleries.
Release Day: Webform Basics Wrap-Up
Blog postThis week, we're wrapping up our series on Webform Basics. In these final lessons of the series, we'll cover administrative tasks such as security, spam control, and results analysis. Even if you're not using Webform, you'll be able to apply the strategies from the "Adding Spam Protection Using Honeypot" lesson to prevent spam on your site.
So far we've been looking at Webform from an administrator's point of view. Now it's time to take a step back and look at Webform from the perspective of anonymous users. We want to make sure that our users can do what we're asking and we're not creating security vulnerabilities. In this lesson, we'll configure permissions for our Webform case study.
In this lesson we'll add spam protection to our webforms using Honeypot module. We'll also take a second look at setting submission limits as a strategy for thwarting form submission abuse.
Additional resources
Introducing the Honeypot form spam protection module for Drupal