REST API Design. Application API API = Application Programming Interface APIs expose functionality of an application or service that exists independently.

Slides:



Advertisements
Similar presentations
Give it a REST already Arnon Rotem-Gal-Oz VP R&D xsights
Advertisements

REST Vs. SOAP.
REST Introduction 吴海生 博克软件(杭州)有限公司.
Introduction to Web Services
REST (Representational State Transfer)
Reinventing using REST. Anything addressable by a URI is called a resource GET, PUT, POST, DELETE WebDAV (MOVE, LOCK)
Building RESTful Interfaces
Chapter 3: Programming Web Services Service-Oriented Computing: Semantics, Processes, Agents – Munindar P. Singh and Michael N. Huhns, Wiley, 2005.
HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
The World Wide Web and the Internet Dr Jim Briggs 1WUCM1.
1 The HyperText Transfer Protocol: HTTP Nick Smith Stuart Alley Tara Tjaden.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Hypertext Transport Protocol CS Dick Steflik.
PL-IV- Group A HTTP Request & Response Header
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.
Web Services 101 James Payne Managing Director for New Media / Advancement July 30, 2013.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
SUNY Polytechnic Institute CS 490 – Web Design, AJAX, jQuery Web Services A web service is a software system that supports interaction (requesting data,
FTP (File Transfer Protocol) & Telnet
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
2: Application Layer1 CS 4244: Internet Software Development Dr. Eli Tilevich.
Application Layer 2 Figures from Kurose and Ross
Designing and Implementing Web Data Services in Perl
Web Architecture & Services (2) Representational State Transfer (REST)
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
RESTful applications Norman White. REST Representational state transfer Key concepts – Client Server architecture built on transferring resources between.
REST - Introduction Based on material from InfoQ.com (Stefan Tilkov) And slides from MindTouch.com (Steve Bjorg) 1.
HTTP1 Hypertext Transfer Protocol (HTTP) After this lecture, you should be able to:  Know how Web Browsers and Web Servers communicate via HTTP Protocol.
Web Server Design Week 4 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/03/10.
1 Seminar on Service Oriented Architecture Principles of REST.
World Wide Web “WWW”, "Web" or "W3". World Wide Web “WWW”, "Web" or "W3"
API Crash Course CWU Startup Club. OUTLINE What is an API? Why are API’s useful? What is HTTP? JSON? XML? What is a RESTful API? How do we consume an.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
Representational State Transfer (REST). What is REST? Network Architectural style Overview: –Resources are defined and addressed –Transmits domain-specific.
Web Technologies Lecture 1 The Internet and HTTP.
Web Services. 2 Internet Collection of physically interconnected computers. Messages decomposed into packets. Packets transmitted from source to destination.
EE 122: Lecture 21 (HyperText Transfer Protocol - HTTP) Ion Stoica Nov 20, 2001 (*)
RESTful Web Services What is RESTful?
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Overview of Servlets and JSP
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Representational State Transfer COMP6017 Topics on Web Services Dr Nicholas Gibbins –
Intro to REST Joe Gregorio Google. REST is an Architectural Style.
National College of Science & Information Technology.
Better RESTFul API – Best Practices
REST- Representational State Transfer Enn Õunapuu
Advanced Web-based Systems | Misbhauddin
Representational State Transfer
Ashish Pandit IT Architect, Middleware & Integration Services
WEB API.
$, $$, $$$ API testing Edition
Service-Oriented Computing: Semantics, Processes, Agents
A gentle introduction to RESTful APIs
REST APIs Maxwell Furman Department of MIS Fox School of Business
REST på Microsoft-stacken
A gentle introduction to RESTful APIs
REST API Design Borrowed heavily from:
Presentation transcript:

REST API Design

Application API API = Application Programming Interface APIs expose functionality of an application or service that exists independently of the API. Examples: Facebook Twitter Google

REST REST stands for Representational State Transfer REST is an architectural style for networked hypermedia applications REST is used to build Web services that are lightweight, maintainable, and scalable. REST is not dependent on any protocol, but almost every RESTful service uses HTTP as its underlying protocol.

RESTful Design Components There are three distinct components involved in RESTful API design: 1.the application 2.the API code 3.the client.

Resources The fundamental concept in any RESTful API is the resource. Resources model objects from the application data model. These resources can be pictures, video files, Web pages, business information, etc. A resource is an object with a type, associated data, relationships to other resources, and a set of methods that operate on it. Each resource has a unique URL

Addressing Resources A RESTful service uses a directory hierarchy like human readable URIs to address its resources. The job of a URI is to identify a resource or a collection of resources. The actual operation is determined by an HTTP verb. The URI should not say anything about the operation or action. This enables us to call the same URI with different HTTP verbs to perform different operations. Bad: Example resource:

Collections Resources can be grouped into collections. Each collection is homogeneous so that it contains only one type of resource. Collections are unordered. Collections are themselves resources as well. Example collection:

Resource Model of an API The resource model of an API consists: 1.Available resources types 2.Their behavior 3.Their relationships The resource model can be viewed as the RESTful mapping of the application data model.

Resource Data Resources have data associated with them. In JSON, just three types of data exist: scalar (number, string, boolean, null). array object Data associated with a resource is modeled as key:value pairs on the JSON object.

JSON Object Example

REST Metadata In addition to exposing application data, resources also include other information that is specific to the RESTful API. Such information includes URLs and relationships. Example: { "href" : " "username" : "jlpicard", " " : "directory" : { "href" : " }, … }

Entry Point A RESTful API needs to have one and exactly one entry point. The URL of the entry point needs to be communicated to API clients so that they can find the API. It is common for the entry point to contain some or all of the following information: Information on API version, supported features, etc. A list of top-level collections. A list of singleton resources Each collection and resource in the API has its own URL. URLs should never be constructed by an API client. Instead, the client should only follow links that are generated by the API itself.

Messages The client and service talk to each other via messages. Clients send a request to the server, and the server replies with a response. Apart from the actual data, these messages also contain some metadata about the message. HTTP Request:

Request Message Example POST Host: MyService.com Content-Type: text/xml; charset=utf-8 Content-Length: 123 Larry US

Response Message Example HTTP/ OK Date: Sat, 23 Aug :31:04 GMT Server: Apache/2 Last-Modified: Wed, 01 Sep :24:52 GMT Accept-Ranges: bytes Content-Length: Cache-Control: max-age=21600, must-revalidate Expires: Sun, 24 Aug :31:04 GMT Content-Type: text/html; charset=iso CS449 Calendar...

Methods Methods are verbs or actions that can be performed on resources Methods can be executed on resources via their URL. Standard methods that have a well-defined meaning for all resources and collections: MethodScopeSemanticsQuality GETCollectionRetrieve all resources in a collectionSafe GETResourceRetrieve a single resourceSafe POSTCollectionCreate a new resource in a collectionN/A PUTResourceUpdate a resourceIdempotent DELETEResourceDelete a resourceIdempotent HEADResourceRetrieve only the response headersSafe OPTIONSResourceList the allowed operations on a resource.Safe

Methods [cont.] GET is Safe. A Safe operation is an operation that does not have any effect on the original value of the resource. PUT and DELETE are Idempotent. An Idempotent operation is an operation that gives the same result no matter how many times you perform it. Note, if you are adding a resource with PUT you have to specify the unique ID of the resource.

Difference between PUT and POST PUT is idempotent while POST is not. No matter how many times you send a PUT request, the results will be same. POST is not an idempotent method. Making a POST multiple times may result in multiple resources getting created on the server. With PUT, it is the client's job to choose a unique name or ID for the resource. With POST, the server decides. This is why POST is not idempotent. There is no difference between PUT and POST if the resource already exists

Options The method OPTIONS is used to get a list of allowed operations on the resource. For example Request: OPTIONS HTTP/1.1 HOST: api.business.com Response: 200 OK Allow: HEAD, GET, PUT

Relationships Resources do not exist in isolation, but have relationships to other resources. A resource representation can contain links to other resources. The representations returned by the service should drive the process flow as in case of a website. When you visit any website, you are presented with an index page. You click one of the links and move to another page and so on. Relationships are defined via link object or href attribute.

Stateless A RESTful service is stateless and does not maintain the application state for any client. A request cannot be dependent on a past request and a service treats each request independently. HTTP is a stateless protocol by design and you need to do something extra to implement a stateful service using HTTP. Example stateful design (not RESTful): Request1: GET HTTP/1.1 Request2: GET HTTP/1.1

HATEOAS HATEOAS = Hypermedia as the Engine of Application State HATEOAS is a constraint of the REST application architecture that distinguishes it from most other network application architectures. HATEOAS is how the web works. Ever notice how the websites amazon.com, google.com, twitter.com etc. don’t come with an instruction manual for using them? You don’t need one. You simply discover the features of a website by following hyperlinks. Nice feature of the web because otherwise every time there was a change to the structure of a website the website user guide would have to be updated, redistributed and reread. Websites are freer to evolve because they are built on the concept of HATEOAS.

HATEOAS API A REST client enters a REST application through a simple fixed URL. All future actions the client may take are discovered within resource representations returned from the server. The client transitions through application states by selecting from the links within a representation or by manipulating the representation in other ways afforded by its media type. In this way, RESTful interaction is driven by hypermedia, rather than out-of-band information (written documentation)

Example Non-HATEOAS Response: { "name": "Alice", } HATEOAS Response: { "name": "Alice", "links": [ { "rel": "self", "href": " } ] }