A gentle introduction to RESTful APIs

Slides:



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

REST - Representational State Transfer
REST Vs. SOAP.
REST Introduction 吴海生 博克软件(杭州)有限公司.
Introduction to Web Services
Building RESTful Interfaces
Thoughts on Architecture for the Internet of Things Group Name: Working Group 2 - Architecture Source: Nicolas Damour, Sierra Wireless
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Web Servers How do our requests for resources on the Internet get handled? Can they be located anywhere? Global?
1 The HyperText Transfer Protocol: HTTP Nick Smith Stuart Alley Tara Tjaden.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
Controling instrument in the RESTful way
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Web Proxy Server Anagh Pathak Jesus Cervantes Henry Tjhen Luis Luna.
CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Java Omar Rana University of South Asia. Course Overview JAVA  C/C++ and JAVA Comparison  OOP in JAVA  Exception Handling  Streams  Graphics User.
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
M i SMob i S Mob i Store - Mobile i nternet File Storage Platform Chetna Kaur.
Python and REST Kevin Hibma. What is REST? Why REST? REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a.
Open Data Protocol * Han Wang 11/30/2012 *
REST - Introduction Based on material from InfoQ.com (Stefan Tilkov) And slides from MindTouch.com (Steve Bjorg) 1.
1 Web Servers (Chapter 21 – Pages( ) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3 System Architecture.
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.
Representational State Transfer (REST). What is REST? Network Architectural style Overview: –Resources are defined and addressed –Transmits domain-specific.
RESTful Web Services What is RESTful?
REST By: Vishwanath Vineet.
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Representational State Transfer COMP6017 Topics on Web Services Dr Nicholas Gibbins –
Using Retrofit framework in implementation of Android REST client David Ante Macan*, Zlatko Stapić, Milan Pavlović* University of Zagreb Faculty of Organization.
REST API Design. Application API API = Application Programming Interface APIs expose functionality of an application or service that exists independently.
A service Oriented Architecture & Web Service Technology.
National College of Science & Information Technology.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Software Project Configuration Management
The Client-Server Model
API (Application Program Interface)
Thoughts on Architecture for the Internet of Things
RESTful Sevices Distributed Objects Presented by: Shivank Malik
Better RESTFul API – Best Practices
Web Development Web Servers.
WEB SERVICES From Chapter 19 of Distributed Systems Concepts and Design,4th Edition, By G. Coulouris, J. Dollimore and T. Kindberg Published by Addison.
WEB SERVICES.
REST- Representational State Transfer Enn Õunapuu
Chapter 11 Object-Oriented Design
Advanced Web-based Systems | Misbhauddin
Hypertext Transport Protocol
CMPE 280 Web UI Design and Development October 24 Class Meeting
Representational State Transfer
Ashish Pandit IT Architect, Middleware & Integration Services
WEB API.
Ashish Pandit, Louis Zelus, Jonathan Whitman
James Blankenship March , 2018
Chapter 27 WWW and HTTP.
SDWIS Prime REST APIs Elinor Keith
$, $$, $$$ API testing Edition
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Web services introduction, application and its future
REST APIs Maxwell Furman Department of MIS Fox School of Business
RESTful Web Services.
REST på Microsoft-stacken
Technical Integration Guide
WEB SERVICES From Chapter 19, Distributed Systems
Web APIs In computer programming, an application programming interface (API) is a set of subroutine definitions, protocols, and tools for building application.
Week 05 Node.js Week 05
Service-Oriented Computing: Semantics, Processes, Agents
A gentle introduction to RESTful APIs
Sending a text message (and more)
Chengyu Sun California State University, Los Angeles
* Web Servers/Clients * The HTTP Protocol
Presentation transcript:

A gentle introduction to RESTful APIs Jeremy Shafer Department of MIS Fox School of Business Temple University

Agenda for today What, in theory, is a RESTful API? The six REST constraints The marriage of REST and HTTP HTTP Methods HTTP Status Codes Common wrinkles and exceptions The abuse of GET Self documenting … not! State matters

Definitions What is a Web API? API stands for Application Programming Interface. A web API allows specifically exposed methods of an application to be accessed and manipulated outside of the program itself. Web APIs use web protocols (HTTP, HTTPS, JSON, XML, etc.). For example, a web API can be used to obtain data from a resource (such as U.S. postal service zip codes) without having to actually visit the application itself (checking usps.com). What is REST? REST is short for Representational State Transfer. REST is a software architectural style… a set of rules and conventions for the creation of an API. A computer scientist by the name of Roy Fielding defined the principles of REST in his 2000 PhD dissertation. Like any theoretical ideal, there are a lot of practical exceptions to Fielding’s principles. But the principles of REST are intended to make APIs and systems that are: efficient, scalable, simple, reliable and modifiable (i.e. future-proof) among other things … all excellent ideals!

The 6 constraints of REST (1) Client-Server architecture – Simply put, RESTful systems separate the systems responsible for storing and processing the data (the server) from the systems responsible for collecting, requesting, consuming, and presenting the data to a user (the client). This separation should be so distinct that the client and server systems can be improved and updated independently each other. Client Server An upgrade to the client should not necessitate an upgrade to the server… and vice versa.

The 6 constraints of REST (2) Statelessness – As far as the server is concerned, all client requests are treated equally. There’s no special, server-side memory of past client activity. The responsibility of managing state (for example, logged in or not) is on the client. This constraint is what makes the RESTful approach so scalable. Be advised! In REST each and every resource request is to convey the application state. That means the state gets transferred with each request!

The 6 constraints of REST (3) Cacheability – Clients and servers should be able to cache resource data that changes infrequently. For example, there are 52 states and other jurisdictions in the U.S.A. That’s not likely to change soon. So, it is inefficient to build a system that queries a database of states each and every time you need that data. Clients should be able to cache that infrequently updated date and web servers should be able to control the duration of that cache. Layered system – A client cannot tell whether it is connected directly to an end server, or to an intermediary along the way. Intermediary servers can also improve system scalability. B A C D As far as the client is concerned, only “A” exists!

The 6 constraints of REST (4) Code on demand (Optional) – Servers can temporarily extend or customize the functionality of a client by transferring executable code. This is constraint is optional. Uniform Interface – This constraint is comprised of 4 additional “constraints” or “principles”. Taken together, these 4 additional principles basically require the API to be consistent with HTTP standards and self describing. That means that, in theory, given an API’s web address, a server should respond with all the available actions and resources at that address. Each subsequent server response should then contain enough information to take additional actions on the resource. This constraint is very rarely realized in practice! A Can I have new feature, please?! Yes! New code!

The marriage of REST and HTTP Roy Fielding was also one of the principle authors of the HTTP specification. Fielding created the REST constraints with HTTP in mind. Part of the power of the REST architectural style is that HTTP was already widely in use before the REST constraints were formally defined. In theory, the six REST constraints we just reviewed could be applied to other protocols, but in practice RESTful APIs are HTTP based.

RESTful API conventions – HTTP Methods * GET – The get method is used to retrieve data from a resource. According to RESTful conventions, GETs are safe to execute over and over. For example: It is safe to run the following GET request as many times as you want: https://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=robot * POST – The POST method would be used to create a data record, or initiate an action. Imagine each POST as being a request to make a amazon purchase. You would want to be careful about doing that more times than necessary! PUT -- The PUT method exists in HTTP. It should be used to update an existing data record. DELETE – The DELETE method exists in HTTP. It should be used to delete a data record. * These are the only two methods you will use this semester.

RESTful API conventions – HTTP Status Codes Every HTTP request results in a status code to be sent back to the client. Request Status Code Server Client 2xx Status codes indicate success. The most common status code is 200, OK. 3xx Status codes indicate that the client needs to do something else to complete the request. Usually this means making the request from a different location. Status code 301 means the resource has been permanently moved somewhere else.

HTTP Status Codes continued 4xx Status codes indicate a client error. That is, the client sent a request that did not make sense. A classic example of this is “404 Not Found”. Try it! Go to https://www.google.com/bad then try going to https://www.temple.edu/bad Notice that both pages report the code 404. That’s not just a coincidence. The internet is built on standards like HTTP and these error codes are part of that standard. 5xx Status codes indicate a server error. That means that the request made by the client appears to be fine. But the server is experiencing some difficulty. A server experiencing some difficulty might report “500 Internal server error” More thorough documentation of the HTTP status codes can be found here: https://www.restapitutorial.com/httpstatuscodes.html

A quick reality check… The REST design constraints are good in theory. However, in practice no one … not even the largest technology companies … implements them perfectly. Three of the most common constraint violations follow.

Wrinkles and exceptions Abuse of the GET method. Again, GET is assumed to be a safe operation that never modifies the state of the resource. However, it has been often contorted into performing other functions… for example: http://exampleapi.xyz?action=ADD&productname=Widget APIs are not self-documenting This RESTful ideal has yet to be fully realized. Even so, some API providers don’t even try! State matters – In the REST design, the burden of managing state is on the client. That, however, raises many security concerns. API providers like the efficiency gains made possible by REST … but there is no one consistent approach to managing state. Next class, we will explore one of those approaches.

Until next time. If you want to get technical about it, most APIs that are described as RESTful, could be better described as “REST-like”… because they violate one or more of the REST constraints. No challenge due for next time. But, if you want to put your knowledge to the test, try to create an example that uses this API: http://www.purgomalum.com/ Or look for other APIs here: https://github.com/toddmotto/public-apis If you are interested in a more detailed reading about REST and Web APIs, the following is suggested (but not required!) reading: The REST API Design Handbook by George Reese