Difference between revisions of "Web Services Examples"

From the Directed Edge Developer Base
Jump to: navigation, search
(Retrieving an item)
(Updating an item)
Line 110: Line 110:
  
 
== Updating an item ==
 
== Updating an item ==
 +
 +
Here we update the item above, but this time add the property ''city''.  This overwrites all current contents of the item.
 +
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<directededge version="0.1">
 +
  <item id="user4">
 +
    <tag>user</tag>
 +
    <property name="city">Berlin</property>
 +
  </item>
 +
</directededge>
 +
</source>
 +
 +
{{CurlPut|user4-update|/user4}}
  
 
== Adding a tag to an item ==
 
== Adding a tag to an item ==

Revision as of 09:33, 24 May 2009

So, now that you've been through the documentation on the API Concepts, XML Format and REST API, let's take a look at a few practical examples of working with the Directed Edge webservices.

For these examples we'll be using the command line tool curl to upload XML to the webservices.

Importing a database

Let's start with a very simple database with three users (with the IDs user1, user2 and user3) and three products (with the IDs product1, product2 and product3).

<?xml version="1.0" encoding="UTF-8"?>
<directededge version="0.1">
  <item id="user1">
    <tag>user</tag>
    <link>product1</link>
    <link>product2</link>
  </item>
  <item id="user2">
    <tag>user</tag>
    <link>product3</link>
  </item>
  <item id="user3">
    <tag>user</tag>
    <link>product2</link>
  </item>
  <item id="product1">
    <tag>product</tag>
  </item>
  <item id="product2">
    <tag>product</tag>
  </item>
  <item id="product3">
    <tag>product</tag>
  </item>
</directededge>

Curl Command (Download XML):

$ curl -T database.xml https://exampledb:password@webservices.directededge.com/api/v1/exampledb

This imports the structure above into the exampledb database.

Exporting a database

Curl Command:

$ curl https://exampledb:password@webservices.directededge.com/api/v1/exampledb

Produces:

<?xml version="1.0" standalone="yes"?>

<directededge version="0.1">
  <item id="user1">
    <tag>user</tag>
    <link>product1</link>
    <link>product2</link>
  </item>
  <item id="user2">
    <tag>user</tag>
    <link>product3</link>
  </item>
  <item id="user3">
    <tag>user</tag>
    <link>product2</link>
  </item>
  <item id="product1">
    <tag>product</tag>
  </item>
  <item id="product2">
    <tag>product</tag>
  </item>
  <item id="product3">
    <tag>product</tag>
  </item>
</directededge>

Which is what we imported just above.

Adding an item

Adds a user with the ID user4 to the database.

<?xml version="1.0" encoding="UTF-8"?>
<directededge version="0.1">
  <item id="user4">
    <tag>user</tag>
  </item>
</directededge>

Curl Command (Download XML):

$ curl -T user4.xml https://exampledb:password@webservices.directededge.com/api/v1/exampledb/user4

Retrieving an item

Curl Command:

$ curl https://exampledb:password@webservices.directededge.com/api/v1/exampledb/user4

Produces:

<?xml version="1.0" standalone="yes"?>

<directededge version="0.1">
  <item id="user4">
    <tag>user</tag>
  </item>
</directededge>

Again, just as we created a moment ago.

Updating an item

Here we update the item above, but this time add the property city. This overwrites all current contents of the item.

<?xml version="1.0" encoding="UTF-8"?>
<directededge version="0.1">
  <item id="user4">
    <tag>user</tag>
    <property name="city">Berlin</property>
  </item>
</directededge>

Curl Command (Download XML):

$ curl -T user4-update.xml https://exampledb:password@webservices.directededge.com/api/v1/exampledb/user4

Adding a tag to an item

Adding a link to an item

Adding a property to an item

Removing a tag from an item

Removing a link from an item

Deleting an item

Finding related items

Doing personalized recommendations