[[TracNav(TracNav)]]
[[TOC]]
Ce document est aussi disponible en [wiki:Fr/AtomApiTutorial/Post Français]
----
== POST ==
You add a new mark on blogmarks.net by posting an Atom entry on a postURI. The postURI is http://api.blogmarks.net/marks.
In the Atom entry, you must specify at least a related link and a title.
=== First example ===
We'll se how to create the most simple allowed blogmark.
Authentication is explained in AtomApiTutorial/Get
The client send
{{{
POST /marks HTTP/1.0
Host: api.blogmarks.net
Accept: application/atom+xml
Content-Type: text/xml; charset=utf-8
Content-length: 267
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="$Username", PasswordDigest="$PasswordDigest", Nonce="$Nonce", Created="$CreationTimestamp"
Znarf Blog
}}}
The server response :
{{{
HTTP/1.1 201 Created
Date: Wed, 09 Mar 2005 11:21:03 GMT
Content-length: 811
Connection: close
Content-Type: application/atom+xml; charset=utf-8
Znarf Blog
2005-03-09T12:21:03Zznarfhttp://api.blogmarks.net/marks/315232005-03-09T12:21:03Z
}}}
=== Second example ===
We'll create a more advanced blogmark.
* In the Atom mapping, tags are called category
* By specifing published=0000-00-00, we say that the blogmarks is private (not published)
* bm:created is the main blogmark date. This is the one which is used to sort blogmarks chronologically
{{{
POST /marks HTTP/1.0
Host: api.blogmarks.net
Accept: application/atom+xml
Content-Type: text/xml; charset=utf-8
Content-length: 535
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="$Username", PasswordDigest="$PasswordDigest", Nonce="$Nonce", Created="$CreationTimestamp"
Znarf BlogThis blog really rox0000-00-002005-03-09
}}}
=== Same code in PHP / Pear HTTP Request ===
{{{
setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader('X-WSSE', 'UsernameToken Username="' . $Username . '", PasswordDigest="' . $PasswordDigest . '", Nonce="' . $Nonce . '", Created="' . $CreationTimestamp . '"');
$xml =
'
Znarf BlogThis blog rox0000-00-002005-03-09';
$req->addRawPostData($xml);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
echo $response->getMessage();
} else {
$code = $req->getResponseCode();
switch ($code) {
case 201:
echo "OK\n";
echo $req->getResponseBody();
break;
default:
echo $code . " Error\n";
break;
}
}
?>
}}}
=== Good practices ===
* '''Don't flood''' : Flooding is posting a lot of blogmarks (say more than 5) and by the way filling the Last Public Marks list. Others users really don't like that. The recommended practice is to specify a bm:created in the past. You may have one if you import marks for example. If you don't have one, we recommand to put the current date without specifying the hour. 2005-03-08Z
----
See also : [wiki:AtomApiTutorial/Get AtomApiTutorial/Get], [wiki:AtomApiTutorial/Put AtomApiTutorial/Put], [wiki:AtomApiTutorial/Delete AtomApiTutorial/Delete]