Home
  • English
  • עברית
  • Home
  • Portfolio
  • Blog
  • Services
  • About us
  • Contact

DrutNet - Drupal .NET API

Submitted by brice on Thu, 04/29/2010 - 17:22
— Tagged as
  • .NET
  • Drupal-planet
  • DrutNet

DrutNet is a .NET API to create client applications that connects to a Drupal site, and allow file upload, node save/load, view get and more.

Introduction
I've created this simple API to connect Drupal with .NET applications easily and quickly, this API was based on an API that I wrote for one of our projects, for this project we had to create a few client application to upload files, connect to desktop application and update the content. I used two different interfaces to cover all my needs, cURL - to upload files; and Services module - to create/ update nodes.

Features Snapshot
DrutNet API has a Services class:

  • Services.Login - Login to Drupal
  • Services.NodeGet - Load a node
  • Services.UserGet - Load a user
  • Services.NodeSave - Save a node

To upload files using the API use the CURL class:

  • Curl.Login - Login to Drupal with cURL, which is required in order to uplaod a file. This login is not the same as the Services login
  • Curl.UploadFile - Upload a file to a CCK file/ image field. The "File form" module provided in the /Drupal Module folder must be enabled on the Drupal site

Source
The source code is stored under GitHub (we didn't publish it in Drupal as apparently it against some the CVS guidelines).

Example
In the source there is a sample project, that demonstrates the use of the API to load/ save a node, and to upload a file.
To test the API follow the instructions bellow (no programing or compiling required when using the):

  1. Place both Drupal modules under '/Drupal Module' in your Drupal installation (e.g. under sites/all/modules):
    - DrutNet sample module - The module creates a DrutNet smaple content type to test the system with the DrutNETSample
    - File form - This module is required for file upload with cURL
  2. Download and enable the required modules
    drush dl cck views features filefield services
  3. Compile the sample project Or use the already compiled program in /Dlls/DrutNETSample.exe
  4. Insert your username password to Drupal and the Drupal site URL


  5. Click on "Login to services", and then click "Login to cURL".


  6. Update an existing node by indicating the node ID, loading it, changing the text and "Save" it.


  7. To test file upload, switch to the Upload tab, choose a file and fill the node ID, CCK field name to attach the file to (in our example we use field_file), and hit the Upload Button

For features or bug report use GitHub project page

Comments

File upload

It is actually possible, and quite easy, to do file uploads and associate them with imagefields using the file.save service, and attaching the resulting fid to your node's imagefield. You need to do it in that order but it is really simple.

  • reply
Submitted by heyrocker (not verified) on Fri, 04/30/2010 - 00:15.

Indeed, there's file.save,

Indeed, there's file.save, that uses base64_encode. Also the PHP docs mention: "Base64-encoded data takes about 33% more space than the original data."
It seems that for bigger files cURL is a better and faster solution, and we don't need to bother we encoding.

But you are right, we should probably implement also Services.Upload - to save the login to cURL.

  • reply
Submitted by Amitaibu on Fri, 04/30/2010 - 09:25.

Implementation of file.save

I've added this function to the API and will release a blog post once it's ready, this will remove the dependency for cURL when uploading files. cURL still give some additional options, like the ability to get the upload progress and better performance.

  • reply
Submitted by brice on Mon, 05/10/2010 - 11:08.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><blockquote>
  • Lines and paragraphs break automatically.
  • Pairs of<blockquote> tags will be styled as a block that indicates a quotation.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

Gizra | Brener 5, Tel-Aviv 63826 Israel | +972-527-587-697 | info@gizra.com