Mezeo Ready Developer Center
February 04, 2012, 06:25:38 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
Author Topic: REST vs WebDAV  (Read 1155 times)
jclouds
Newbie
*
Posts: 1


View Profile
« on: October 04, 2009, 12:52:50 PM »

Hello.

Can someone help connect the WebDAV vs REST api for me?  I'd like to make a test that ensures objects I create in REST are accessible via WebDAV and visa versa.

Ex.  I assume containers == WebDAV folders?

Can you show an example of ReST commands to create an object and WebDAV commands to retrieve it?

Thanks,
-Adrian
jclouds 
Logged
Travis McLane
Mezeo Employee
Newbie
*****
Posts: 21



View Profile
« Reply #1 on: October 05, 2009, 11:25:23 AM »

Hello Adrian,

You are correct that containers == WebDAV folders.
I will use curl for these examples to keep it language agnostic.


Here is the directory structure I will create:

/Folder1/Folder2/readme.txt

This will be accessible using WebDAV using the path:

/dav/Folder1/Folder2/readme.txt

First we retrieve our rootContainer:

# curl -u <username> https://example.com/v2 | xmlstarlet fo
# Enter host password for user '<username>':

Code:
<?xml version="1.0" encoding="UTF-8"?>
<cloud xmlns:xlink="http://www.w3.org/1999/xlink">
  <rootContainer xlink:href="https://example.com/v2/containers/A7A59250-037E-11DE-A315-AB091792CCC5" xlink:type="simple"/>
  <contacts xlink:href="https://example.com/v2/contacts" xlink:type="simple"/>
  <shares xlink:href="https://example.com/v2/shares" xlink:type="simple"/>
  <projects xlink:href="https://example.com/v2/projects" xlink:type="simple"/>
  <metacontainers xlink:href="https://example.com/v2/metacontainers" xlink:type="simple"/>
  <account xlink:href="https://example.com/v2/account" xlink:type="simple"/>
  <tags xlink:href="https://example.com/v2/tags" xlink:type="simple"/>
  <recyclebin xlink:href="https://example.com/v2/recyclebin" xlink:type="simple"/>
</cloud>


First we create the directory structure using the REST API.

Folder1 Creation:

# curl -u <username> -X POST -H 'Content-Type: application/vnd.csp.container-info+xml' https://example.com/v2/containers/A7A59250-037E-11DE-A315-AB091792CCC5/contents -d <container><name>Folder1</name></container>
# Enter host password for user '<username>':

Response:
https://example.com/v2/containers/CC70F4F0-B1C8-11DE-A6F2-2BC186563653


Folder2 Creation:

Notice the use of the Response URI in the second post to create a container within the contents of the first container that was created.

#curl -u <username> -X POST -H 'Content-Type: application/vnd.csp.container-info+xml' https://example.com/v2/containers/CC70F4F0-B1C8-11DE-A6F2-2BC186563653/contents -d <container><name>Folder2</name></container>
# Enter host password for user '<username>':

Response:
https://example.com/v2/containers/34861C78-B1C9-11DE-B9A2-5FC690F26B5E

We now have the container hierarchy created:

/Folder1/Folder2

Let us add a file to this sub-container:

testfile.txt contents:
-----------------
This is test file
-----------------


# curl -u <username> https://example.com/v2/containers/34861C78-B1C9-11DE-B9A2-5FC690F26B5E/contents -F "file=@testfile.txt;filename=testfile.txt"
# Enter host password for user '<username>':

Response:
https://example.com/v2/files/DDFF7948-B1C9-11DE-A575-0F1EFAB4E7D3


Retrieve the file contents using REST to verify the contents:

# curl -u <username> https://example.com/v2/files/DDFF7948-B1C9-11DE-A575-0F1EFAB4E7D3/content

Response:

-----------------
This is test file
-----------------


Accessing the above-created file using WebDAV:

WebDAV keeps the same container structure that was builtup in the above example.
The only difference is that it prepends '/dav/' to the beginning of the URL.

This makes the URL to retrieve the file from:

https://example.com/dav/Folder1/Folder2/testfile.txt

WebDAV uses GET to retrieve file contents:

# curl -u <username> -X GET https://example.com/dav/Folder1/Folder2/testfile.txt
# Enter host password for user '<username>':

-----------------
This is test file
-----------------

Logged
Pages: [1]
 
Jump to:  

© Mezeo Software. All rights reserved. | Privacy Policies | Contact Us | Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC