2012-03-05 2 views
1

私はRESTを初めて使いましたが、シンプルなWebサービスを構築しましたが、どのURLフォーマットが正しいか簡単に説明するのは難しいです。この単純なREST WebサービスのURLはどうすればよいですか?

このサービスでは、請求書を作成し、一連の簡単な承認フェーズを実行することができます。

(1)XML形式ですべての請求書を読む

GET: http://localhost/webapp/ws/invoices/555 

(3:

GET: http://localhost/webapp/ws/invoices 

(2)XML形式で1枚の請求書を(例:請求書ID = 555)を読みます。 )新しい請求書提出:請求書の属性( "USERID"、 "totalprice" など)を備えた

POST: http://localhost/webapp/ws/invoices 

はのPOSTパラメータのように含まれています単純なHTMLフォーム。

(4)請求書を承認:アクションで

POST: http://localhost/webapp/ws/invoices/action 

は(例: "ユーザーID = 123"、invoiceid = 567、 "ACTION = APPROVE" または "拒否" など)属性のような含まれています単純なHTMLフォームのPOSTパラメータ。

これはうまく動作しますが、RESTfulなWebサービスの外観に近いものでもありますか?

アドバイスをいただきありがとうございます。

ロブ

答えて

1

私はどうなるの承認プロセスのための私見:あなたはIDで識別される既存のリソースを変更しようとしていると

PUT: http://localhost/webapp/ws/invoices/555 

(4)請求書を承認(555)ので、変更される属性を渡すだけで済みます。

+0

ありがとう、それは良い考えです。 –

3

URLはAPIをRESTfulにしません。リソースとその状態遷移(リンクとフォームを通じて)を明確に表現し、クライアントを実装に結び付ける帯域外情報を避けることが重要です。 A RESTful Hypermedia API in Three Easy Steps coversこのコンセプトはきれいです。

1)すべてのクライアントの開始点をよく知っているルートリソースを作成し、利用可能なサービスを検出できるようにします(これは、Browersで使用されているURLと同じである可能性があります)。Acceptヘッダーを使用して、 media-typeを返す必要があります)。

GET:これは、クライアントに伝えるnext要素とページ分割コレクションですhttp://localhost/webapp/invoices

<invoices href="/webapp/invoices"> 
    <invoice href="/webapp/invoices/555"/> 
    <invoice href="/webapp/invoices/554"/> 
    <invoice href="/webapp/invoices/553"/> 
    <invoice href="/webapp/invoices/552"/> 
    ... 
    <search href="/webapp/invoices/" method="get"> 
     <query type="xpath" cardinality="required"/> 
    </search> 
    <next href="/webapp/invoices?page=2" method="get"/> 
    <create-draft href="/webapp/invoices" method="post"> 
     <total-price type="decimal" cardinality="optional"/> 
     ... user should be picked up automatically based on the authorised user posting the form ... 
     ... add other optional and required parameters here. ... 
    </create-draft> 
</invoices> 

http://localhost/webapp

<webapp href="/webapp"> 
    <invoices href="/webapp/invoices"/> 
    ... any other services ... 
</webapp> 

2)あなたの請求書のため

GETを収集リソースを作成します。どのように次のページを取得する。十分な請求書がない場合(例:、5つの請求書と各ページは10を含むことができます)、next要素は表示されません。同様に、リクエスタに請求書を作成する権限がない場合、create-draftフォームは含まれません。

次のページを取得すると、次のようになります。

GET:http://localhost/webapp/invoices?page=2

<invoices href="/webapp/invoices"> 
    <invoice href="/webapp/invoices/545"/> 
    <invoice href="/webapp/invoices/544"/> 
    <invoice href="/webapp/invoices/543"/> 
    <invoice href="/webapp/invoices/542"/> 
    ... 
    <search href="/webapp/invoices/" method="get"> 
     <query type="xpath" cardinality="required"/> 
    </search> 
    <next href="/webapp/invoices?page=3" method="get"/> 
    <prev href="/webapp/invoices" method="get"/> 
    <create-draft href="/webapp/invoices" method="post"> 
     <total-price type="xs:decimal" cardinality="optional"/> 
     ... user should be picked up automatically based on the authorised user posting the form ... 
     ... add other optional and required parameters here. ... 
    </create-draft> 
</invoices> 

3)ご請求書の項目のリソースを作成します

GET:http://localhost/webapp/invoices/555

<invoice href="/webapp/invoice/555"> 
    ... details go here ... 
    <reject href="/webapp/invoices/555" method="delete"> 
     <reason type="xs:string" cardinality="required"/> 
    </reject> 
    <approve href="/webapp/invoices/555" method="put"> 
     ... add approval parameters here ... 
    </approve> 
</invoices> 

同様に、ユーザーが再認証を許可されていない場合請求書を承認または承認すると、それらの要素は表示されません。請求書がすでに承認されている場合も同様です(キャンセルフォームがある場合もあります)。

関連する問題