Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)
How to Build APIs with the Services Module
-
Upload
acquia -
Category
Technology
-
view
819 -
download
2
Transcript of How to Build APIs with the Services Module
![Page 1: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/1.jpg)
Building Web Services with Drupal 7March 19th, 2014 - Joe Shindelar - @eojthebrave !
http://lb.cm/acquia-servicesmodule
![Page 2: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/2.jpg)
Hi, I’m Joe …
@eojthebraveLullabot / Drupalize.Me
![Page 3: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/3.jpg)
Services & Drupal 7http://lb.cm/acquia-servicesmodule !
Drupalize.Me Series: Building Web Services with Drupal 7
![Page 4: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/4.jpg)
Lets GO!‣ What are web services and why do I want one? ‣ Drupal 7 services module core concepts and features. ‣ How to test your new web service. ‣ The future.
![Page 5: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/5.jpg)
What Are Web Services?The W3C defines web service as: a software system designed to support interoperable machine-to-machine interaction over a network.
API stands for Application Programmer Interface API’s specify how software components should interact with one another.
APIs
![Page 6: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/6.jpg)
A standardized, and documented way to access and interact with your applications content and features.
![Page 7: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/7.jpg)
Examples of Existing Web Services‣ Twitter ‣ Netflix ‣ Amazon S3, EC2, etc. ‣ Yahoo weather API ‣ Flight tracking data
![Page 8: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/8.jpg)
Why Web Services?‣ Provide access for mobile devices (internet of things) ‣ Legacy integration ‣ Digital asset management system ‣ Partners who need/want your data - weather, MLS listing, etc. ‣ Social media
![Page 9: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/9.jpg)
Services & Drupal 7Services Module - 7.x-3.x http://drupal.org/project/services !
Drupal 7.x Information is specific to Drupal 7 though applicable to other versions as well.
![Page 10: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/10.jpg)
/videos/theming-component
/api/v1/video/1381.json
![Page 11: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/11.jpg)
Chunks vs. BlobsIt is easier for machines to understand structured content like JSON or XML than a giant blob of text. !
Drupal already stores data in structured chunks (fields) making it an ideal backend for a data API.VIDEO NODE
VIDEO ASSET
![Page 12: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/12.jpg)
Drupal’s Data & ActionsData Nodes, users, comments, views, etc. !
Actions User login, node create, and trigger sending a password reset email.
![Page 13: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/13.jpg)
Server TypesServices allows many server formats.
!
‣ REST ‣ XML-RPC ‣ Soap ‣ AMF-PHP, and more …
![Page 14: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/14.jpg)
Request & Response Formats‣ Response: JSON, XML, JSONp, YAML, etc.
!
‣ Request: application/json, application/xml, multipart/form-data
![Page 15: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/15.jpg)
Authentication‣ Session Authentication ‣ OAuth Authentication
Pro Tip: Want to do API keys? Use 2-legged OAuth.
![Page 16: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/16.jpg)
Resources‣ Provide basic CRUD support
for data objects. ‣ Provide additional actions. ‣ Map requests to PHP code ‣ Likely 1st place you’ll write
custom code.
![Page 17: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/17.jpg)
Resource Definitions‣ A URI ‣ Access control ‣ Callback function(s) ‣ Arguments & Paramaters ‣ services.services.api.php
![Page 18: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/18.jpg)
Resource DocumentationKnowing what resources are available and especially what arguments/parameters they accept can be tricky.
!
‣ Code is the canonical source. ‣ http://drupal.org/projet/services_tools module helps.
![Page 19: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/19.jpg)
Services Endpoint(s)Basic configuration for your sites web service API. ‣ Base URL, eg. api/v1. ‣ Server type. ‣ Request & response formats accepted. ‣ Authentication type. ‣ Resources enabled.
![Page 20: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/20.jpg)
Views & Services‣ http://drupal.org/project/services_views
!
‣ Provides a resource to expose existing views. ‣ Create new views and expose them as a resource.
![Page 21: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/21.jpg)
Testing Your APIRequest: GET : http://example.com/resource/{ID} Accept: application/json !
Response: HTTP 200 Ok Content-type: application/json {“message”: “Hello World!”}
![Page 22: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/22.jpg)
Services Tools : https://drupal.org/project/services_tools
What to Test?
![Page 23: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/23.jpg)
cURL‣ It’s not pretty but it is ubiquitous. ‣ http://curl.haxx.se/
curl --data '{"title":"hello world!","type":"page"}' --header
"Content-Type:application/json" http://localhost/demos/
services-7x/docroot/api/v1/node!
![Page 25: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/25.jpg)
The Future?Drupal 8 has a built in REST server! !
Try it now with REST WS in contrib.
![Page 26: How to Build APIs with the Services Module](https://reader033.fdocuments.in/reader033/viewer/2022060107/554ae1f6b4c905a37c8b4dbb/html5/thumbnails/26.jpg)
Review‣ Web services allow access to your applications data
and actions. ‣ Services module for Drupal 7:
• Easy, extensible, and flexible