Other architectures are externally built or expanded

Similar documents
RESTful Services. Distributed Enabling Platform

Develop Mobile Front Ends Using Mobile Application Framework A - 2

RESTFUL WEB SERVICES - INTERVIEW QUESTIONS

REST Easy with Infrared360

04 Webservices. Web APIs REST Coulouris. Roy Fielding, Aphrodite, chp.9. Chp 5/6

Web Services Week 10

Designing RESTful Web Applications. Ben Ramsey

HTTP, REST Web Services

Web API Best Practices

Introduction to RESTful Web Services. Presented by Steve Ives

Copyright 2014 Blue Net Corporation. All rights reserved

REST AND AJAX. Introduction. Module 13

ReST 2000 Roy Fielding W3C

CS 43: Computer Networks. HTTP September 10, 2018

Protocols. Application Layer FTP, HTTP, SSH, IMAP. Transport Layer TCP, UDP. Internet Layer IP. Link Layer Ethernet, WiFi

INF5750. RESTful Web Services

REST in a Nutshell: A Mini Guide for Python Developers

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

INFO/CS 4302 Web Informa6on Systems

Kim Dalsgaard. Co-owner of, and Software Designer at Trifork Athene Co-founder of Aarhus Ruby Brigade

REST Web Services Objektumorientált szoftvertervezés Object-oriented software design

Distributed Systems. 03r. Python Web Services Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017

Web-APIs. Examples Consumer Technology Cross-Domain communication Provider Technology

CS October 2017

Microservices. SWE 432, Fall 2017 Design and Implementation of Software for the Web

REST API s in a CA Plex context. API Design and Integration into CA Plex landscape

Restful Interfaces to Third-Party Websites with Python

Web Presentation Patterns (controller) SWEN-343 From Fowler, Patterns of Enterprise Application Architecture

REST A brief introduction

RESTful Web Services. 20-Jan Gordon Dickens Chariot Solutions

Reviewing the API Documentation

Backends and Databases. Dr. Sarah Abraham

A Brief Introduction to REST

Unraveling the Mysteries of J2EE Web Application Communications

WWW, REST, and Web Services

Services Web Nabil Abdennadher

Working with the Seagull Framework. By Demian Turner, Seagull Systems

DatabaseRESTAPI

TAXII 2.0 Specification Pre Draft

Lesson 14 SOA with REST (Part I)

Backends and Databases. Dr. Sarah Abraham

Web Architecture Review Sheet

REST. And now for something completely different. Mike amundsen.com

Webspeed. I am back. Enhanced WebSpeed

Lesson 15 SOA with REST (Part II)

Widget Toolkits CS MVC

Teach your (micro)services speak Protocol Buffers with grpc.

Introduction to REST Web Services

Managing Remote Medical Devices Through The Cloud. Joel K Young SVP of Research and Development & CTO Digi International Friday, September 9 11:30AM

Lecture 6 Application Layer. Antonio Cianfrani DIET Department Networking Group netlab.uniroma1.it

RESTful Web services

An Overview of. Eric Bollens ebollens AT ucla.edu Mobile Web Framework Architect UCLA Office of Information Technology

Ansible Tower API Guide

Session 12. RESTful Services. Lecture Objectives

CONFIGURING DIFFERENT APIS IN ARUBA 8.X

Web, HTTP and Web Caching

CS 498RK FALL RESTFUL APIs

A Comparison of Service-oriented, Resource-oriented, and Object-oriented Architecture Styles

Aim behind client server architecture Characteristics of client and server Types of architectures

REST - Representational State Transfer

Service Oriented Architectures (ENCS 691K Chapter 2)

Understanding RESTful APIs and documenting them with Swagger. Presented by: Tanya Perelmuter Date: 06/18/2018

What is REST? ; Erik Wilde ; UC Berkeley School of Information

Oracle RESTful Services A Primer for Database Administrators

Session 8. Reading and Reference. en.wikipedia.org/wiki/list_of_http_headers. en.wikipedia.org/wiki/http_status_codes

Backend Development. SWE 432, Fall Web Application Development

Data Management CS 4720 Mobile Application Development

To Kill a Monolith: Slaying the Demons of a Monolith with Node.js Microservices on CloudFoundry. Tony Erwin,

Module 3 Web Component

Controller/server communication

Application Design and Development: October 30

CS 5450 HTTP. Vitaly Shmatikov

WWW. HTTP, Ajax, APIs, REST

PUSH services. Document revision 1.0 Date of Issue: 04 October 2018 Date of revision: 04 October Nick Palmer.

Coding Intro to APIs and REST

Writing APIs in Lumen

There is REST and then there is REST. Radovan Semančík November 2017

StorageGRID Webscale NAS Bridge Management API Guide

Mobile Data: How to avoid the latency trap when using web services

Web 2.0 and AJAX Security. OWASP Montgomery. August 21 st, 2007

How to work with HTTP requests and responses

Intro to XML. Borrowed, with author s permission, from:

The 60-Minute Guide to Development Tools for IBM Lotus Domino, IBM WebSphere Portal, and IBM Workplace Applications

Rich Web Applications in Server-side Java without. Plug-ins or JavaScript

Manipulating Web Application Interfaces a New Approach to Input Validation Testing. AppSec DC Nov 13, The OWASP Foundation

Mock Objects and the Mockito Testing Framework Carl Veazey CSCI Friday, March 23, 12

Header Status Codes Cheat Sheet

Evaluation Guide for ASP.NET Web CMS and Experience Platforms

Twelve Patterns for Hypermedia Service Architecture

Apache Wink Developer Guide. Draft Version. (This document is still under construction)

Google Plugin for Eclipse

DATABASE SYSTEMS. Database programming in a web environment. Database System Course,

TRANSFER MANAGER 2017

REST over HTTP. Ambient intelligence. Fulvio Corno. Politecnico di Torino, 2015/2016

Discussion #4 CSS VS XSLT. Multiple stylesheet types with cascading priorities. One stylesheet type

SOA: Service-Oriented Architecture

Etanova Enterprise Solutions

HTTP Reading: Section and COS 461: Computer Networks Spring 2013

Controller/server communication

COMPUTER NETWORKS AND COMMUNICATION PROTOCOLS. Web Access: HTTP Mehmet KORKMAZ

Transcription:

RESTful interfaces http://rest.elkstein.org/ (but not Section 11) http://net.tutsplus.com/tutorials/other/a-beginners-introduction-to-http-and-rest/ and for a laugh (or cry) : http://www.looah.com/source/view/2284 https://dev.twitter.com/docs/api/1.1

Other architectures are externally built or expanded Some applications provide a platform for development, and they do not ultimately know what kinds of tools will sit on their platform. Operating systems are obviously a massive example of this, and are totally geared to application-layer expansion (but obviously not optimised for OS expansion). But there are less enormous examples: plug in or extension architectures, (Eclipse, Chrome, Firefox) Server APIs (via RPC or RESTful interfaces)

Data over Tools (John Weigand -- living architectures podcast SE radio) tools are manipulating data (requirements, test cases, source code, etc). tools are interesting, but the data is MORE interesting, independent of the tools. Old view in software tooling: focus on the tools; the data is a side effect. New view: more attention to the data, and tools just facilitate data-manipulation. (point to debate: this is another version of OO!?)

Thinking in a RESTful way (John Weigand -- living architectures podcast SE radio) You need to look at things differently. The traditional framework solution focuses on the call chain much more centrally, and the data gets to be something that s carried along.! Whereas in RESTful approaches, the focus is on understanding the concepts, and making sure you get the right resources in place, and that s the central focus. So yes, it s a different mindset. And it takes practice. But the importance of having a good interface applies just as well in both cases.

Neutral RESTful architecture; OO tools (John Weigand -- living architectures podcast SE radio) The Java language is going to continue to be valuable.! But in terms of establishing loosely coupled architecture, the boundary that you want when you re language neutral doesn t want to talk about inheritance.! It really wants to focus on the data and how does it connect. And then enable a range of ways for that data to be exposed.! So they re complementary: we don t try to have the whole world talk in terms of OO concepts, but in local toolkits, we still leverage that.

API for the CanaFind sys. CLIENT Camera GPS Finder UI Searcher UI ItemList=findItem(image,loc) submititem(image, loc) Finder API Searcher API Indexer/Tagger SERVER DATABASE This isn t an extensible ( living ) architecture BUT: We don t know what people who build the clients are going to do. We know they re constrained significantly (all they can do is submit items, and get lists of items) But there might be a lot they can do within those constraints. We might want to think of *all* the directions they can go, and provide an API that allows more freedom and extensibility.

This is an RPC approach CLIENT Camera GPS Finder UI Searcher UI ItemList=findItem(image,loc) submititem(image, loc) Finder API Searcher API Indexer/Tagger This approach involves Remote Procedure Calls Note that the calls are specialised verbs (submitimage( ), find( )) The data must be pre-defined, meaning we both the client and the server must agree on data types. SERVER DATABASE

RESTful Interfaces the web is an existence proof of a massively scalable distributed system that works really well, and we can take ideas from that to build integrated systems more easily. Martin Fowler "Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual statemachine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use." - Roy Fielding

Another way: REST REpresentative State Transfer http://en.wikipedia.org/wiki/representational_state_transfer

The Basics request CLIENT SERVER response

If your Client is a browser CLIENT request response SERVER BROWSER URL HTML SERVER

If your Client is an Application CLIENT request response SERVER GET, POST, PUT, DELETE HTTP request APP RESTful URI SERVICE some structured data

REST principles Resources are identified by Uniform Resource Identifiers (URIs) Resources are manipulated through their representations Messages are self-descriptive and stateless Multiple representations are accepted or sent

RESTful APIs Instead of using application specific verbs, the operations are pre-set verbs from the HTTP operations: GET, PUT, DELETE, POST. RESTful APIs provide a uniform interface to a set of (typically) hierarchically arranged Resources (the nouns) Resources are located at URI s: Universal Resource Identifiers which are stored in Representations Requests are sent to the server, and the server responds with a text record that can be parsed into a response object.

The HTTP API HTTP provides a really simple set of operations GET (retrieve a resource) POST (store a new resource) PUT (store a resource at an existing URI) DELETE (remove a resource) Requests are sent to the server, and the server responds with a text record that can be parsed into a response object.

Overall architecture CLIENT GPS Camera Finder UI Searcher UI GET {image, location, radius} POST {image, location} Finder API Searcher API Indexer/Tagger SERVER DATABASE

Getting a web page: Cana Find Provides media type for message. Such as: text, html, structured data (xml...), images (jpeg...) GET /index.html 200 OK... Content/Type: text/html... <entire web page> RESTful SERVICE response codes such as: 200: OK 201: Created 400: Bad Request 404: Not Found 500: Internal Server Error content or payload of the message. In this case, a web page.

Using Parameters GET /photos?loc=49.2609...+-123.249...&radius=400 Cana Find 200 OK... Content/Type: xml... <photo> <id>1</id> <purl>/photos/1.jpg</purl> <loc> 49.2609...+-123.249</loc> </photo> <photo> <id>18</id> <purl>/photos/18.jpg</purl> <loc> 49.2609...+-123.249</loc> </photo> RESTful SERVICE

Using Parameters POST /photos data= {"loc"=49.26..+-123.249..., "photo"=...image data...} Cana Find 200 OK... Content/Type: json... {"id": 239877870, "lat":49.26.., "lon":123.249.., "purl":/photos/239877870.jpg } RESTful SERVICE

Client and Server (pseudo)code uri="/photos?loc=49.26..." response=open(uri).read() GET /photos?loc=49.2609...+-123.249...&radius=400 Cana Find photolist=xmlparse(response, "photo") foreach photo in photolist: dosomethinggood(photo) 200 OK... Content/Type: xml... <photo> <id>1</id> <purl>/photos/1.jpg</purl> <loc> 49.2609...+-123.249</loc> </photo> <photo> <id>18</id> <purl>/photos/18.jpg</purl> <loc> 49.2609...+-123.249</loc> </photo> RESTful SERVICE r=elisasparserequest($_get) if ($r.resource=='photos'): //find all relevant photo objs plist=canasearch(r.loc, r.rad) header="200 OK" content=plist

Principles... Safe systems: HTTP is a robust protocol. To maintain that robustness, GET, PUT and DELETE operations must be idempotent. meaning: you can run them again and again with no duplication of functionality. Stateless: All client state remains on the client. The server doesn t retain any state about the client. Connectedness: Do not force the client to recall internally the structure of the resources on the server. Provide relevant links inside returned resources. URI design: URIs represent nouns not verbs. Put resources there, not behaviour. Each resource has four behaviours: GET, PUT, POST, DELETE.

GET; PUT; DELETE: Idempotence is Important! Even if you don t get a response from an idempotent operation, you can safely perform it again. https://mathieu.fenniak.net/wp-content/uploads/2013/05/idempotent_prototype_4.html#

Canafind resources /photos: GET: returns a list of photo objects DELETE: you can t do that. Bad request: 400 PUT: you can t do that. Bad request: 400 POST: inserts a new photo into photos.! /photos/id: GET: returns the photo resource DELETE: deletes the photo resource PUT: you can t do that. Bad request: 400 POST: you can t do that. Bad request: 400 http://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/ 200 OK Everything is working 201 OK New resource has been created 204 OK The resource was successfully deleted! 304 Not Modified The client can use cached data! 400 Bad Request The request was invalid or cannot be served. The exact error should be explained in the error payload. E.g. The JSON is not valid 401 Unauthorised The request requires an user authentication 403 Forbidden The server understood the request, but is refusing it or the access is not allowed. 404 Not found There is no resource behind the URI. 422 Unprocessable Entity Should be used if the server cannot process the enitity, e.g. if an image cannot be formatted or mandatory fields are missing in the payload.! 500 Internal Server Error API developers should avoid this error. If an error occurs in the global catch blog, the stracktrace should be logged and not returned as response.

CanaFind API spec GET PUT POST DELETE /photos (id, loc, rad) returns of photo objects s/f: 200/404 400 (bad request) (id, loc, rad) inserts new photo into /photos/ s/f: 200/404 400 (bad request) /photos/id (id, loc, rad) returns photo resource s/f: 200/404 400 (bad request) 400 (bad request) deletes photo resource s/f: 200/404 /photos/ searchjob/ 400 (bad request) 400 (bad request) (string) returns a job id for the search s/f: 202 (accepted) 400 (bad request) /photos/ searchjob/id returns currently available results for job 400 (bad request) 400 (bad request) deletes the search job (cancels search) s/f: 200/404

Twitter s RESTful(???) API could have used DELETE request DELETE statuses/id/ could have used DELETE request DELETE direct_messages/id/

So remember: All resources must elegantly handle: GET/PUT/POST/DEL Resources are nouns, not verbs Don t ask the client to remember the internal server structure send back links in your XML/JSON if you need the client to surf over to another resource location Use the most precise possible response code Make sure GET/PUT/DEL are idempotent All behavioural state must remain client-side.