Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Writing A Custom Services Resource

Video loading...

Transcript language code: 

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:03
    Writing A Custom Services Resource
  • 0:05
    with Joe Shindelar
  • 0:07
    JOE SHINDELAR: What do you do when Services doesn't provide you
  • 0:10
    with the data you need, or there isn't already another module
  • 0:13
    integrating with Services to provide you with the actions you want?
  • 0:17
    You write your own, of course.
  • 0:19
    One of the best parts about the services module
  • 0:22
    is its extensible architecture and how quick and easy
  • 0:25
    it is to write our own customized resources that return exactly
  • 0:28
    the data we need and perform exactly the actions we want.

Writing a Custom Services Resource


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}'

Log in or sign up to download companion files.
Additional resources: