Table of Contents
This protocol is implemented by the RestNaruto
and RestNarutoService
classes. Those classes should
be used wherever possible so that future protocol changes can be dealt with
seamlessly.
This chapter is dedicated to the REST protocol as it is deployed for the Naruto project. The intended audience for this document is either a protocol developer or a developer in a language besides PHP wishing to connect with this protocol.
All requests can use either the GET or POST HTTP method. However, methods containing sensitive information should use the POST method so the information does not appear in web logs and is a little more secure.
All requests contain the HTTP header X_WEBPLANK_VERSION, the
Naruto Client version, and X_WEBPLANK_AUTH, the caller's authentication
info produced by the NatutoCredentials
class.
The PATH_INFO is used to identify the
Naruto
method being called. For example,
/GetForumList is identified a getForumList()
. Most
of them are obvious, but some methods may differ for obscurity or
versioning. See the METHOD_* constants in the
NaturoConstants
class for the full list.
All requests contain the seq query parameter which is a client-unique transaction number. This parameter to help line up requests and responses.
There are currently no passwords in requests. However, in the future, the may be.
Whenever possible passwords should not be sent over the network.
With the use of the NarutoCredentials
, the
sending of the caller's password is avoided.
Rather than sending a plain text passwords in these cases, a non-trivial 2-way encoded algorithm is used and additionally the HTTP POST method should used to reduce visibility. A reversible algorithm, no matter how clever, can ultimately be reversed; so there is no substitute for a secure network tunnel.
All responses are in the forum of XML messages. Every method will either return the expected response or an Exception response. All responses have the following layout
<Naruto xmlns:naruto="http://naruto.sourceforge.net/rest"> <ResponseType
version="0.0.1" seq="89365064"> ... </ResponseType
> </Naruto>
Element Naruto - The root element is always Naruto.
Element ResponseType - The element name will be replaced with the appropriate method response name, like GetForumListResponse.
Attribute version - The Naruto version deployed on the server.
Attribute seq - The sequence number passed in the request.
A typical XML exception response is shown below. See the E_*
constants in the NaturoConstants
class for the
full list of error codes, but be aware that new codes could be
added.
<Naruto xmlns:naruto="http://naruto.sourceforge.net/rest"> <Exception version="0.0.1" seq="89365064"> <code>2</code> <message>User hacker invalid.</message> </Exception> </Naruto>
The REST protocol service code may only throw the E_PROTO and
E_COMM exceptions; however, it will return any exception it receives
from the Naruto
implementation it is
configured to use. For example. E_AUTH could be thrown if the caller is
not authenticated by the message board.
The following exception message demonstrates the case where there are secondary exception details.
<Naruto xmlns:naruto="http://naruto.sourceforge.net/rest"> <Exception version="0.0.1" seq="19107746"> <code>2</code> <message>Could not authenticate user</message> <secondarySource>ssoService</secondarySource> <secondaryCode>SSO123</secondaryCode> <secondaryMessage>Remote host unavailable</secondaryMessage> </Exception> </Naruto>
Table 6.1. Rest Method Quick List
Request Path | Request Parameters | Response |
---|---|---|
/GetForumList | seq, [parentId], [userName] | <GetForumListResponse> |
/GetTopicList | seq, forumId, [limit], [offset], [maxAge], [userName] | <GetTopicListResponse> |
/GetTopic | seq, forumId, topicId [userName] | <GetTopicResponse> |
/GetRecentTopics | seq, [limit], [maxAge], [userName] | <GetRecentTopicsResponse> |
/AddForumTopic | seq, forumId, topic, body, [userName] | <AddForumTopicResponse> |
/AddTopicPost | seq, forumId, topicId, subject, body, [userName] | <AddTopicPostResponse> |
/MergeTopics | seq, forumId, topicId, intoTopicId | <MergeTopicsResponse> |
/GetUnreadPrivateMessageCount | seq, [userName] | <GetUnreadPrivateMessageCountResponse> |
/GetUser | seq, userId [email] | <GetUserResponse> |
/GetUserByName | seq, userName [email] | <GetUserByNameResponse> |
/GetUserBySession | seq, sessionId [email] | <GetUserBySessionResponse> |
The Ack element serves as a confirmation that a request has been completed or that the answer to the question is true.
<Ack/>
The Attributes element encapsulates the
NarutoDO
class' attribute functionality. This is
a sub element of the Topic and Forum elements.
<Attributes> <entry name="a">A</entry> ... </Attributes>
Required Attributes: entry.name
The list may be empty.
The Decimal element represents the number value response to a question.
<Decimal>123</Decimal>
The Exception element encapsulates the
NarutoException
class.
<Exception version="0.0.1" seq="19107746"> <code>2</code> <message>Could not authenticate user</message> <secondarySource>ssoService</secondarySource> <secondaryCode>SSO123</secondaryCode> <secondaryMessage>Remote host unavailable</secondaryMessage> </Exception>
Required Elements: code, message
The Forum element encapsulates the
NarutoForum
and
NarutoCategory
classes.
<Forum type="category">
<id>3</id>
<name>Fun With Toys</name>
<url>http://forum.com/forums?f=1</url>
<parentID>1</parentId>
<lastUpdated>1</lastUpdated>
<topicCount>1</topicCount>
<Attributes/>
</Forum>
Required Elements: id, name, url
The forum type attribute is only set for when it is a category. A category is a special type of forum that only contains sub-forums and no topics.
The Forum element encapsulates and array
NarutoForum
and
NarutoCategory
objects.
<Forums>
<Forum/>
...
</Forums>
The list may be empty.
The Id element represents the object id for a Topic, Forum or Category. It can be a string.
<Id>123</Id>
The Topic element encapsulates the
NarutoTopic
class.
<Topic>
<id>3</id>
<name>Fun Toys</name>
<url>http://forum.com/topics?t=3</url>
<forumD>1</forumId>
<lastUpdated>1</lastUpdated>
<postCount>1</postCount>
<Attributes/>
</Topic>
Required Elements: id, name, url, forumId
The Topics element encapsulates and array
NarutoTopic
objects.
<Topics>
<Topic/>
...
</Topics>
The list may be empty.