UPDATE: Please read this article for a much more detailed explanation on how to get started with Drupal Services. Here is a post on github that summarizes some stuff as well.
Low and behold the awesomeness of the Drupal Services module. However, the documentation seems scarce on how to actually use the beast. So here are some examples to get you performing your services for humanity. Special thanks to Joseph, the Stormin' Mormon (a non drupal programmer) for helping me figure out this fiasco.
If you don't already have it installed, you really should get the Poster plugin for Firefox (yes Chrome is really cool, but the Poster plugin seems funky in Chrome).
Now to create a service, we'll start with the basics... go to Site Building -> Services -> Add, and enter some stuff like this:
| Name | my_services |
| Endpoint title | My Services |
| Server | REST |
| Path to endpoint | my_services_path |
Ignore the other fields for now. Click 'Save' to, you guessed it, save your new service.
Next up, we need to enable some Resources for our Service. Go to Site Building -> Services -> List, then click 'Edit Resources' next to your Service.
Expand the 'system' resource and check the box for the 'connect' resource, then click, you guessed it again, the 'Save' button.
You are good to go, now to test our new System Connect Resource from our Service. Open up Firefox, then open the Poster plugin.
Listed below are examples on how to use Poster with Drupal Services.
Note: by default services return XML results, but if you'd like JSON instead, just add .json to the end of the URL you are calling. And of course, replace 'localhost' with your domain.
URL: http://localhost/my_services_path/system/connect (OR http://localhost/my_services_path/system/connect.json)
Actions: POST
URL: http://localhost/my_services_path/user/login (OR http://localhost/my_services_path/user/login.json)
Content Type: application/x-www-form-urlencoded
Parameters (Tab), use the 'Add/Change' button to add these name/value pairs as parameters:
Content to Send (Tab): Click the 'Body from Parameters' button
Actions: POST
URL: http://localhost/my_services_path/user/logout (OR http://localhost/my_services_path/user/logout.json)
Actions: POST
I'll add more examples after the poles swap places.
Comments
Techie Talks (not verified)
Tue, 11/15/2011 - 23:43
Permalink
Thanks for sharing this. It
Thanks for sharing this. It really helped me a lot understand how to start developing a mobile app and integrate it with drupal.
Eduardo (not verified)
Tue, 01/17/2012 - 15:31
Permalink
Ok. I don't understand the
Ok. I don't understand the part of: system->connect. I don't have the access. Please, send me a e-mail.
tyler
Tue, 01/17/2012 - 16:06
Permalink
Hi Eduardo, Please check out
Hi Eduardo, Please check out the system->connect explanation in this article for more information about the system connect service resource.
Basically, when you make a call to system connect, it returns to you information about the user that made the call (user id, session id, etc).
Add new comment