私はWebアプリを設計していたところ、自分のAPIをRESTful Webサービスとしてどのように設計するべきかについて考えるのをやめました。今のところ、私のURIのほとんどは汎用であり、さまざまなWebアプリに適用できます。
GET /logout // destroys session and redirects to /
GET /login // gets the webpage that has the login form
POST /login // authenticates credentials against database and either redirects home with a new session or redirects back to /login
GET /register // gets the webpage that has the registration form
POST /register // records the entered information into database as a new /user/xxx
GET /user/xxx // gets and renders current user data in a profile view
POST /user/xxx // updates new information about user
SOとグーグルを探し回った後、私はここでかなり間違っていると感じています。
から始めて/logout
、おそらく私は実際にはGET
何もしないので、セッションを破棄してリダイレクトするPOST
というリクエストの方が適切な場合があります。そして、用語は留まるべきですか?/logout
GET
/logout
何について/login
と/register
。に変更/register
する/registration
ことはできますが、サービスに根本的な機能が変更されることはありません。
/user
リソースを公開することはありません。たぶんそれはなんとか利用できるでしょう。たとえば、ユーザーを取るmyUser
:
foo.com/user/myUser
または
foo.com/user
エンドユーザーは、URIに余分な冗長性を必要としません。しかし、どちらが視覚的に魅力的ですか?
このRESTビジネスに関するSOで他のいくつかの質問に気づきましたが、できればここに示したものについてのガイダンスを本当に感謝します。
ありがとう!
更新:
私もいくつかの意見をお願いします:
/user/1
対
/user/myUserName