Alik Levin's

Clarity, Technology, and Solving Problems | PracticeThis.com 

June, 2010

  • Alik Levin's

    Notes on RESTful Architecture – II. Read Only RESTful Services

    • 0 Comments

    From the book RESTful .NET: Build and Consume RESTful Web Services with .NET 3.5.

    RESTful binding, behavior, hosting, and contracts

    WebHttpBinding – uses http transport and text encoder.

    WebBehavior – end point behavior to dispatch messages based on URIs and HTTP verbs.

    WebSericeHost – provides RSTful services hosting configuration [WebServuceHostFactory for IIS/WAS].

    WebOperationContext – contains state of the incoming request and outgoing response.

    • QueryParameters – holds the collections of query string parameters. Available in IncomdingRequest of WebOperationContext.

    WebGetAttribute – applied to methods to handle GET requests

    WebInvokeAttribute – applied to methods to handle POST, PUT, DELETE.

    • Method - a property that specifies what HTTP method to use [POST – default, PUT, or DELETE]

    UriTemplate – specifies the template, mapping between the URI and a method

    • “/{Variable}/{Variable}/{Variable}”
    • “*”
    • “/”
    • “{/{Variable}/*}”
    • “/Literal/{Variable}”
    • “/Literal/NestedLiteralSpecialCase”
    • “/Search?q={query}” – for passing parametrs via query string and collecting it using QueryParamenters object.

    Serialization methods

    Message - represents return value for RESTful service

    • Not usually used with non-RESTful WCF [strong type are used instead]
    • More complex coding to process the message
    • Complete control of the XML

    DataContract 

    • Preferred method non-RESTful regular WCF
    • Cannot create attributes, elements only

    XnkSerializer

    • Better for RESTful WCF
    • [XmlSerialization()] for [OperationContract]
    • Can create attributes vs. elements [XmlAttribute(Attribute=”name”)] instead [DataMemeber]

    Hybrid (DataContract + Message)

    • Use DataContract for serialization.
    • Use Message.CreateMessage for return type.
    Related Books
  • Alik Levin's

    Notes On RESTful Architecture - I

    • 0 Comments

    This post is a summary of notes I am taking while reading a book RESTful .NET: Build and Consume RESTful Web Services with .NET 3.5.

    Resources and URI’s

    • RESTful services model the interaction with user agents based on resource.
    • The first thing to do is to determine which resources you’re going to expose.
    • A resource is any information that you want to make available to others.
    • Some resources are static…, and some resources are dynamic.
    • Once you’ve identified the resources you’ll map then to URI’s.

    URI design

    • All resources are uniquely identified by a URI.
    • The idea behind REST is to design your URIs in a way that makes logical sense based on your resource set (vs. GUIDS or/and funky query strings)
    • When designing the associations between resources and URI’s, it may be useful to map them as if you were designing a browsable website.

    Uniform Interface

    • User agents only interact with resources using the prescribed HTTP verbs.
    • The four main verbs are:
      • GET
        • Retrieves a resource.
        • Guaranteed not to cause side-effects (SAFE).
        • Cacheable.
      • POST
        • Creates a new resource.
        • Unsafe, effect of this verb isn’t defined by HTTP.
      • PUT
        • Updates an existing resource.
        • Used for resource creating when client knows URI.
        • Can call N times, same thing will always happen (idempotent).
      • DELETE
        • Removes a resource.
        • Can call N times, same thing will always happen (idempotent).

    Checklist for building RESTFul architecture:

    • Decide what your recourses are.
    • Map the resources to URIs.
    • For each URI define it’s media types [HTTP Content-Type]:
      • XML [application/xml, text/xml - deprecated].
      • RSS/Atom [atom more recent, devs like it, APP or AtomPub protocol].
      • XHTML [application/xhtml+xml].
      • JSON [application/json]
      • More at www.microformats.org

    Related Books

Page 2 of 2 (5 items) 12