Tuesday, June 21, 2016

Design a RestFul Service


While REST stands for Representational State Transfer, which is an architectural style for networked hypermedia applications, it is primarily used to build Web services that are lightweight, maintainable, and scalable. A service based on REST is called a RESTful service. REST is not dependent on any protocol, but almost every RESTful service uses HTTP as its underlying protocol. In this article, I examine the creation of RESTful services with HTTP.

Features of a RESTful Services

Every system uses resources. These resources can be pictures, video files, Web pages, business information, or anything that can be represented in a computer-based system. The purpose of a service is to provide a window to its clients so that they can access these resources. Service architects and developers want this service to be easy to implement, maintainable, extensible, and scalable. A RESTful design promises that and more. In general, RESTful services should have following properties and features, which I'll describe in detail:

http://www.drdobbs.com/web-development/restful-web-services-a-tutorial/240169069

  • Representations: JSON or XML
  • Messages: HTTP Request and Response
    • [ Verb, URI, HTTP Version, Request Header and Request Body ] and Response [ HTTP version, Response Code, Response Header, Respnose Body ]
    • Sample GET and POST requests
  • URIs : Way to address Resources
    • Suppose we have a database of persons and we wish to expose it to the outer world through a service. A resource person can be addressed like this http://MyService/Persons/1
    • Query Parameters in URI


  • Uniform interface
    • RESTful systems should have a uniform interface. HTTP 1.1 provides a set of methods, called verbs, for this purpose
    • What are safe, idepmotent operations
    • PUT vs POST
  • Stateless
    • A request cannot be dependent on a past request and a service treats each request independently
  • Links between resources
    • Let's consider the case in which a client requests one resource that contains multiple other resources. Instead of dumping all these resources, you can list the resources and provide links to them. Links help keep the representations small in size.

  • Caching
    • Caching is the concept of storing the generated results and using the stored results instead of generating them repeatedly if the same request arrives in the near future. This can be done on the client, the server, or on any other component between them, such as a proxy server.


Extra Information:
http://www.restapitutorial.com/lessons/whatisrest.html#
http://www.restapitutorial.com/lessons/restquicktips.html
http://stackoverflow.com/questions/630453/put-vs-post-in-rest
http://stackoverflow.com/questions/1284381/why-is-it-a-bad-practice-to-return-generated-html-instead-of-json-or-is-it
https://www.sitepoint.com/json-vs-xml/

No comments:

Post a Comment