티스토리 툴바

REST, revisited

2010 2010/07/20 09:00
REST에 대해 문외한일 때 글 하나 쓰면서 그린 그림
사용자 삽입 이미지

  • Representational State Transfer (REST)
  • a simpler alternative to SOAP- and Web Services Description Language (WSDL)-based Web services ... 하지만, 일민형이 만난 웹서비스 전문가에 따르면 REST가 시작은 쉽지만 갈수록 첩첩산중이라 WS-*가 깊이 들어가면 도리어 쉽다고 하는데...
  • REST defines a set of architectural principles by which you can design Web services that focus on a system's resources, including how resource states are addressed and transferred over HTTP by a wide range of clients written in different languages. 출처: http://www.ibm.com/developerworks/webservices/library/ws-restful/
  • 정작 처음 등장한 논문 Roy Fielding's dissertation, "Architectural Styles and the Design of Network-based Software Architectures." 을 통해서는 반향이 적었다.
  • a concrete implementation of a REST Web service follows four basic design principles:
    • Use HTTP methods explicitly. (고전인 RFC 2616 다시 보기)
      • To create a resource on the server, use POST.
      • To retrieve a resource, use GET.
        • Web caching tools (crawlers) and search engines에 의해 의도치 않는 상태 변환을 막으려면 파라미터 대신 POSTㄴ
          • POST /users HTTP/1.1
            Host: myserver
            Content-Type: application/xml
            <?xml version="1.0"?>
            <user>
            <name>Robert</name>
            </user>
      • To change the state of a resource or to update it, use PUT.
        • PUT /users/Robert HTTP/1.1
          Host: myserver
          Content-Type: application/xml
          <?xml version="1.0"?>
          <user>
          <name>Bob</name>
          </user>
      • To remove or delete a resource, use DELETE.
    • Be stateless.
      • REST Web services need to scale to meet increasingly high performance demands.
      • Stateful 모형Stateful Design
      • Stateless 모형Stateless Design
      • A stateless service not only performs better, it shifts most of the responsibility of maintaining state to the client application. ... the server is responsible for generating responses and for providing an interface that enables the client to maintain application state on its own
      • This aspect of RESTful Web service design can be broken down into two sets of responsibilities as a high-level separation
        • Server: 상태가 없으니 캐시 하기 좋고, 상태 대신 네비게이션 위한 링크를 포함
        • Client application: Cache-Control response header 이용해서 캐시 여부 결정하고 Conditional GET 활용하며, 매번 독립적인 요청임
    • Expose directory structure-like URIs.
      • Think of a URI as a kind of self-documenting interface
      • the structure of a URI should be straightforward, predictable, and easily understood
        • One way to achieve this level of usability is to define directory structure-like URIs.
        • http://www.myservice.org/discussion/topics/{topic
        • http://www.myservice.org/discussion/2008/12/10/{topic} a.k.a http://www.myservice.org/discussion/{year}/{day}/{month}/{topic}
        • Some additional guidelines
          • Hide the server-side scripting technology file extensions (.jsp, .php, .asp)
          • Keep everything lowercase.
          • Substitute spaces with hyphens or underscores.
          • Avoid query strings as much as you can.
          • Instead of using the 404 Not Found code if the request URI is for a partial path, always provide a default page or resource as a response.
    • Transfer XML, JavaScript Object Notation (JSON), or both.
      • Common MIME types used by RESTful services
        • application/json
        • application/xml
        • application/xhtml+xml

설정

트랙백

댓글