잊지 않겠습니다.

오늘 회사에서 대성씨의 REST에 대한 소개와 REST URI에 대한 내용을 들으면서 전부터 posting 할려고 했던 내용을 Posting 해보자 싶었다. 

  

일단, ASP.NET MVC Framework와 동일하게 진행되었던 ASP .NET의 프로젝트중 하나가 ASP.NET에서의 RESTFUL 이용 방법이였고, 이러한 방법자체가 ASP .NET MVC Framework에 같이 통합이 되어있는 상태이다.

  

기본적으로 Route에 추가하는 RouteHandler에서 회사에서 사용되는 uri.py의 기능과 동일한 기능을 사용하게 된다.

예를 들어.. User/Details/456 이라는 sub-uri를 보게 되면, User-Detail-ID 의 형태를 가지고, User의 Detail한 상태를 알아 볼 수 있는 URI에서의 정보를 제공할 수 있게 된다.

  

MVC에서 RouteHandler가 움직이는 원리는 다음에 포스팅 하기로 하고... 일단은 ASP .NET에서 권장하는 기본적인 Controller의 Action method name, 즉 동작(Action)에 대한 기본 명명법은 다음과 같다.

Action

Sample URL

Description

Details

/Product/Details/5

Displays a single resource such as a database record. For example, displays a single Product with an Id of 5.

Index

/Product/Index

Displays a collection of resources. For example, displays all of the products in the products database table.

Create

/Product/Create

Displays a form for creating a new resource. For example, displays a form for creating a new product.

Insert

/Product/Insert

Inserts a new resource into the database. Typically, you redirect to another action after performing an Insert.

Edit

/Product/Edit/5

Displays a form for editing an existing resource. For example, displays a form for editing a product with an Id of 5.

Update

/Product/Update/5

Updates existing resources in the database. Typically, you redirect to another action after performing an Update.

Destroy

/Product/Destroy/5

Displays a page that confirms whether or not you want to delete a resource from the database.

Delete

/Product/Delete/5

Deletes a resource from the database. Typically, you redirect to another action after performing a Delete.

Login

/Home/Login

Displays a login form.

Logout

/Home/Logout

Logs out a user. Typically, you redirect to another action after performing a Logout.

Authenticate

/Home/Authenticate

Authenticates a user name and password. Typically, you redirect to another action after performing an Authenticate.

  

 여기에서 주목할 점이, Update와 Delete, Destroy이다. REST에서 권장하는 HttpMethod인 PUT과 DELETE를 사용하지 않는 이유는 기본적인 ASP.NET MVC Framework에서는 PUT과 DELETE를 사용하고 있지 않기 때문이다. 기본적인 설정에서 사용하고 있지 않는 설정을 권장사항에 넣기 힘들어서 아무래도 Update와 Delete가 따로 Action으로 분류를 시키고 있는 것 같다. 

  

기본적인 MapRoute 방법자체는 다음과 같다.

             routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

 각각의 Route의 이름과 Controller, Action, 그리고 필요하다면 그에 따른 parameter의 이름을 이용한 MapRoute를 작성시키고 있다. 여기에서 {controller}의 이름은 RegularExpression을 지원하기 때문에, 기본적인 REST 서버들과 거의 유사하게 움직인다. (정확히는 모른다. --)

Posted by Y2K
,