In this lesson Joe walks through making authenticated requests to our API with cURL. Although cURL can be a bit verbose when making authenticated requests it serves as a good way to talk about all the headers that are a required and a lowest common denominator for how you could accomplish authentication in just about any language or application.
Example commands
curl http://services-demo.lan/api/v1/user/login -d '{"name":"admin","pass":"admin"}' -H "Content-type: application/json" -H "Accept: application/json"
curl http://services-demo.lan/api/v1/system/connect -X POST
curl http://services-demo.lan/api/v1/system/connect -H "Cookie: SESS60f8c5b86739b7e326223b4ef35867b2=A86XHGJWlnDcMOGcArbOT-qHrsIi5P2NrcoNTXwWluw" -H "X-CSRF-Token: T77haXwD7JKOJsBlKP3p3kLbjQO96bQWvGJAE1_PUZM" -X POST
curl http://services-demo.lan/api/v1/user/login -X POST -H "Content-type: application/json" -H "Accept: application/json"
In this lesson Joe walks through making authenticated requests using the Chrome REST Console Plugin
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.
All the power of views made available to your API. Really, what else is there to say? In this lesson Joe walks through installation and basic configuration of the services views module which provides the ability to expose views as resources via the services module.
Additional resources
In addition to using views to expose lists of things via our API we can also take advantage of views exposed filters to allow API consumers more control over the data they are receiving in a request. In this lesson Joe looks at accessing views exposed filters via REST requests by adding an exposed filter to both of the perviously created views and then walking through how the configuration of the view changes the behavior of the filter when used via the services API.
In addition to the built in support for core's data and actions the services module also provides a robust framework for exposing the data and actions of our custom modules as an API. In this lesson Joe writes a basic module which creates a custom resource for saving and retrieving a "checked in" status for an authenticated user.
Example commands:
Check a user's status
curl http://localhost/demos/services-7x-test/docroot/api/v1/drupalsquare/1 -H "Accept: application/json"
Check-in a user
curl http://localhost/demos/services-7x-test/docroot/api/v1/drupalsquare/checkin -X POST -H "Content-type: application/json" -H "Accept: application/json" -d '{"uid":1}'
Additional resources
An API that exposes data and actions to a 3rd party is only as good as the documentation for that API. Without good documentation no one will be able to make use of the API you just spent so much energy creating. In this lesson Joe shows some of his favorite API documentation examples and then walks through creating some basic documentation for the resource we created in the previous lesson.
Additional resources
Example - GitHub API Documentation
Example - Recurly Documentation
http://apiary.io - tool to assit in writing good documentation
What Is Drupal?
FreeTo learn more about how to get started with Drupal, also see our Introduction to Drupal guide.
In this lesson we take a look at Drupal, the open source Content Management System. We learn about the major components of a Drupal site and the library of constantly evolving tools available for working with Drupal. We find out how to see who uses it, by looking at DrupalShowcase.com and Drupal case studies on Drupal.org, among others. We look at Drupal's major features, such as Modules.
With this overview we have some context as we move forward into the series.
Additional resources
In this lesson we're going to break down the "Drupal stack" to understand what pieces are working here and how they relate to each other. We'll take a tour of the major components of Drupal itself, like nodes and users, and then have a brief discussion about ways of organizing content.
Additional resources
In this lesson we're going to start building our site for Mom and Pop, Inc. We're starting off by working on our content, to get things filled out a little. First, we'll create an About Us page with the basic info for the store, like address and opening hours. Then we'll create our first article, which welcomes people to the new site, and see how the two core content types, Basic page and Article, are different from each other. Then we'll tweak our main navigation so our tabs display correctly, and finish things off by looking at block management. We'll remove the "Powered by Drupal" block and add a new block to the site for our weekly specials.
Additional resources
This lesson offers a tour of some of the most basic tools for content management in Drupal. We're going to walk through and explain the following pieces:
- Content
- Comments
- Navigation
- Blocks
Additional resources
For this lesson we're going to get hands-on and play around in our administration area a little. We're going to review the site information for our new site, and then change things by setting the site name to match our case study.
Additional resources
In this lesson we're going to start off with the Drupal administrative interface. We'll take a tour of the major elements and get you oriented to what is where.
Additional resources
Modules allow you to turn on and off functionality within your Drupal website. There are two types of modules: core modules, which come with Drupal itself, and contributed modules, which are provided for free by the Drupal community and available for download from Drupal.org. In this lesson we're going to look at the module administration page, and walk through finding and installing modules. We'll wrap things up by discussing how you remove a module from your site, and the difference between disabling and uninstalling.
Additional resources
The easiest way to wrap your head around how modules work is to try installing and configuring a couple of them. This section will cover how to install, enable, and configure a contributed module called Using Drupal, 2nd edition
One of the most powerful features of Drupal is its rich, fine-grained access control system, based around the concept of users, roles, and permissions. In this lesson we'll explain what these pieces are, and how they work together. We'll also discuss the user profile and various user account settings we can manipulate.
Additional resources
When you open the floodgates for your users to become active participants in content creation, one of the inevitable things that comes up is the issue of content moderation—that is, ensuring that abusive, vulgar content and unsolicited advertising or spam is kept off the site and stays off. In this lesson, we'll look at using an automated spam detection, with Mollom, as well as manual spam prevention.
Additional resources
Drupalize.Me Guide: Using Drupal Book by O'Reilly Media
Note: Mollom is EOL (End Of Life). See this blog post by Drupal community member Jeff Geerling for alternative solutions.
This lesson takes a look at working with the already existing entities in Drupal such as users and nodes and demonstrates some best practices for working with them in your own custom module. We'll focus on writing code that will work with any entity type and isn't hard coded to work with just nodes or just entities.
Additional notes:
There is a typo in the video. Joe created the variable $types = 'comment'; in one spot and then used it as entity_load($type, ... which obviously wouldn't work because the later is missing an 's' on the end. The downloadable code for this video doesn't have the typo.
Additional resources
This chapter shows how to cluster different form elements into fieldsets as well as how to expand the Forms API renderable array a tree that preserves the structure and hierarchy of the form. We'll expand the Form Fun example module and talk about the #tree property. This video uses krumo() and dsm() functions. You will need to download, install, and enable the devel module to use these functions. These functions allow you to see what variables are available to you. To accomplish the same task without using the devel module, you can add the following snippet to your module: drupal_set_message('' . print_r($vars, true) .'');
Note: There is a typo in the code used in this video. The function form_fun_tree()
is missing a parameter, and should be as follows function form_fun_tree($form, &$form_state)
.
This lesson demonstrates the bare minimum needed to create a custom entity type and to load an Entity from the database. We’ll look at implementing a minimum viable hook_entity_info, talk about the relationship between the Entity API and the Schema API and use entity_load to retrieve a single entity record from the database.
Note, although it would be considered best practices to name the entity with the name of the module, e.g. videoentity_video, we did not include the module name prefix here because it is tedious to type it all out and to say "videoentity_video" without confusing people.
In the next lesson we'll cover the various entity classes and how they work. However, if you just want to get straight to using your entity and doing things like $entity = entity_load();
you'll need to declare a controller for your new entity type. Simply add this 'controller class' => 'EntityAPIController'
in hook_entity_info()
. That will get you started, and well talk about what exactly that line does in the next lesson.
Note: the video doesn't mention the 'primary key'
element in the schema array (although it is in the code). This bit is necessary for the schema to install properly and work with the Entity API so if you're following a long make sure you add that part as well.
Additional resources
This video goes through the process of creating a configuration form in order to save settings to the variables table in the database, and how to integrate those variables into your module.
Correction
The $item
array in the function demo_menu()
should be named $items
, to match the return $items;
line. (Either that or return $items;
should be fixed to return $item;
.) Just make sure the array you are building matches the name of the variable you are returning.