yohei-y:weblog

XML と REST/Web サービス関連の話題が中心の weblog です

2005-03-09

Restifying excite 翻訳

今日は excite 翻訳の REST インターフェースを考えた。

まずは簡単な翻訳

POST /translation HTTP/1.1
Host: rest.excite.co.jp
Content-Type: application/xml

<?xml version="1.0"?>
<input xmlns="http://ns.excite.co.jp/translation"
    xml:lang="en" out="ja">
REST stands for REpresentational State Transfer.
</input>
HTTP/1.1 OK
Content-Type: application/xml

<?xml version="1.0"?>
<output xmlns="http://ns.excite.co.jp/translation" xml:lang="ja">
REST は REpresentational State Transfer の略です。
</output>

これは以下のようにする案もある。

POST /translation?i=ja&o=en HTTP/1.1
Host: rest.excite.co.jp
Content-Type: text/plain

REST stands for REpresentational State Transfer.
HTTP/1.1 OK
Content-Type: text/xml; charset=utf-8

REST は REpresentational State Transfer の略です。

今度は Web ページ翻訳の例。

POST /translation HTTP/1.1
Host: rest.excite.co.jp
Content-Type: application/xml

<?xml version="1.0"?>
<input xmlns="http://ns.excite.co.jp/translation"
    xml:lang="en" out="ja" type="url">
http://rest.blueoxen.net/cgi-bin/wiki.pl
</input>
HTTP/1.1 OK
Content-Type: application/xml

<?xml version="1.0"?>
<output xmlns="http://ns.excite.co.jp/translation" xml:lang="ja">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <!-- 翻訳したもの -->
  </html>
</output>

これも以下のほうが使いやすいかもしれない

POST /translation?i=ja&o=en HTTP/1.1
Host: rest.excite.co.jp
Content-Type: text/plain

http://rest.blueoxen.net/cgi-bin/wiki.pl

http:// で始まるので Content-Type などから類推する。

HTTP/1.1 OK
Content-Type: text/html; charset=Shift_JIS

<HTML>
  <!-- 翻訳結果 -->
</HTML>

REST の雰囲気わかるかな?

ラベル: ,