RESTful Web Services for Upload

download RESTful Web Services for Upload

of 25

Transcript of RESTful Web Services for Upload

  • 8/3/2019 RESTful Web Services for Upload

    1/25

    By Judy Hsu

    April 21, 2011

  • 8/3/2019 RESTful Web Services for Upload

    2/25

    ` What is REST?

    ` What is RESTful Web Services

    ` Characteristics of RESTful Web services

    ` SOAP v.s. REST Web services` Demo with SoapUI and WADL

    ` References

  • 8/3/2019 RESTful Web Services for Upload

    3/25

  • 8/3/2019 RESTful Web Services for Upload

    4/25

    ` Representational State Transfer

    ` A style of softwarearchitecture forhypermedia system

    suchas World WideWeb

    ` Theterm was defined by Roy Fielding in 2000` Fielding is one oftheauthors of HTTP (Hypertext

    Transfer Protocol) spec 1.0 and 1.1

    ` REST itself is not a spec or software. It is a set of

    best practices and principles.` clients and servers

    ` Requests and responses arebuiltaround thetransfer

    of representations of resources

  • 8/3/2019 RESTful Web Services for Upload

    5/25

    ` Use HTTP methods(get,post,put,delete) explicitly

    ` Resource-centric. Usebase URIs suchas

    http://demo.com/books

    Nouns instead of verbs are used.` Oftentransfer XML or JSON but canbeany other

    valid internetmediatype

    ` Be stateless

  • 8/3/2019 RESTful Web Services for Upload

    6/25

    ` Web services implemented using HTTP and the

    principles of REST

    ` Analternativeto SOAP and WSDL based web

    services` Adopted by mainstream web 2.0 service providers

    E.g. Google, Yahoo, Twitterand Facebook.

    ` RESTful Web services v.s. POX

  • 8/3/2019 RESTful Web Services for Upload

    7/25

    ` Explicit use of HTTP methods that follow defined

    protocol

    ` Basic REST design To createa resource onthe server, use POST

    To retrievea resource , use GET

    To updatea resource, use PUT

    To deletea resource, use DELETE

  • 8/3/2019 RESTful Web Services for Upload

    8/25

    ` Non RESTful sample

    GET /getBook title = Contact HTTP/1.1

    ` RESTful sampleGET /books/Contact HTTP/1.1

    Content-Type:application/xml

  • 8/3/2019 RESTful Web Services for Upload

    9/25

    ` Non RESTful sampleGET /addBook?title= Contact HTTP/1.1

    ` RESTful sample

    POST /books HTTP/1.1

    Content-Type:application/xml

    Contact

  • 8/3/2019 RESTful Web Services for Upload

    10/25

    `

    Non RESTfulGET / updateBook?title=Contact&newTitle=AlienHTTP/1.1

    ` RESTful

    PUT /books/Contact HTTP/1.1

    Content-Type: application/xml

    Alien

  • 8/3/2019 RESTful Web Services for Upload

    11/25

    ` Non RESTful

    GET / deleteBook?title=Contact HTTP/1.1

    ` RESTfulDELETE /books/Contact HTTP/1.1

    Content-Type: application/xml

  • 8/3/2019 RESTful Web Services for Upload

    12/25

    ` In REST, first class objects areexposed as

    resources. They canbeaccessed directly.

    ` Nouns are used instead of verbs.

    ` Resource representations are interconnected, E.g.

    if you retrievea list ofbooks fromanauthor. Each

    book should contain its own URI and you shouldbeableto traverseto eachbook.

  • 8/3/2019 RESTful Web Services for Upload

    13/25

    ` In REST, first class objects areexposed as

    resources. They canbeaccessed directly.

    ` Nouns are used instead of verbs.

    ` Resources are interconnected, E.g. if you retrieve

    a list ofbooks fromanauthor. Eachbook should

    contain its own URI and you should beabletotraverseto eachbook.

  • 8/3/2019 RESTful Web Services for Upload

    14/25

    ` Best practiceto set correct MIME typeto

    guarantee valid response for clients

    ` XML, JSON,YAML, ATOM and any other validinternetmediatype for requestand response

    ` SoapUI inthe response panel can display

    XML,JSON,HTML. Italso can display raw data

    which contains HTTP response code, header, etc.

  • 8/3/2019 RESTful Web Services for Upload

    15/25

  • 8/3/2019 RESTful Web Services for Upload

    16/25

    SOAP REST

    HTTP as transport HTTP as transport

    WSDLand schema for service

    operationand input/output (standard)

    WADL(not standard). Also WSDL 2.0

    starts to support REST web services as

    well (not standard either)

    SOAP as protocol including soapheaderand soap fault

    HTTP as protocol, including HTTPmethods, headerand response code

    XML for requestand response

    message

    XML, JSON, ATOM,YAML and any

    other valid internetmediatype for

    requestand response

    Java JAX-WS spec to standardize

    creationand consumption of soap

    web services

    JAX-RS spec to standardize creation

    and consumption of soap web

    services

  • 8/3/2019 RESTful Web Services for Upload

    17/25

    ` SOAP provides more defined interfaceand may begoodfor distributed applications. REST is considered lighterand more resilientto changes.

    ` However, strongtyped SOAP WSDL canbebad forloosely coupled distributed systems. (Didnt ECIF sufferfromthatas well?) Also, REST may notbe lighter dueto plumbing work required

    ` In REST, clients need to know less about serverprocess. Mainly, they interact with interconnected links oftheir interest.

  • 8/3/2019 RESTful Web Services for Upload

    18/25

    ` Bandwidth is limited and more important. E.gMobil apps or PDAs

    `

    TheWeb services are stateless

    ` The service producerand consumerhaveamutual understanding ofthe contextand contentbeing passed along sincethere is no formaldescription

    ` Otherthan XML is desired as format

  • 8/3/2019 RESTful Web Services for Upload

    19/25

    ` A formal contract is required forthe interface.

    WSDL is used as formal contract.

    `

    Complex non functional requirements suchastransaction, security, addressingare involved.

    With REST, developers need to build more ofthe

    plumbing .

  • 8/3/2019 RESTful Web Services for Upload

    20/25

    ` Spring 3.0 has new features includingthe

    RestTemplate class whichenables clients to

    interact with REST web services. HTTP method

    conversionto convert HTML GET and POST toPUT or DELETE (since HTML only supports GET

    and POST)

    ` RESTEasy is a Jboss projectthat provides variousframeworks forbuilding REST Web services.

  • 8/3/2019 RESTful Web Services for Upload

    21/25

    Use SOAPUI to call a yahoo traffice web services

    live

  • 8/3/2019 RESTful Web Services for Upload

    22/25

  • 8/3/2019 RESTful Web Services for Upload

    23/25

    ` http://rest.elkstein.org/

    ` http://igorpolevoy.blogspot.com/2011/01/java-rest-with-ease.html

    ` http://en.wikipedia.org/wiki/Representational_State_Transfer

    ` http://tomayko.com/writings/rest-to-my-wife

    ` https://www.ibm.com/developerworks/webservices/library/ws-restful/

    ` http://restxdemo.mulesoft.org/static/demo/start.html

    ` http://restx.mulesoft.org)` http://www.peej.co.uk/articles/restfully-delicious.html

    ` https://connections.nwie.net/forums/html/topic?id=b1c58801-aa80-4dae-a145-ca2e7b43a37d

    ` http://www.taranfx.com/rest-vs-soap-using-http-choosing-the-right-webservice-protocol#

    ` http://www.oracle.com/technetwork/articles/javase/index-137171.html

    ` http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/

  • 8/3/2019 RESTful Web Services for Upload

    24/25

    ` Restful Web Services by Leonard Richardsonand

    Sam Ruby (OReilly)

    http://ebookee.org/dl/Restful-WebServices-

    Leonard-Richardson/ (free 14 days trial)

  • 8/3/2019 RESTful Web Services for Upload

    25/25