Designing and Implementing Web Data Services in Perl

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Pierre-Johan CHARTRE Java EE - JAX-RS - Pierre-Johan CHARTRE
REST - Representational State Transfer
REST Vs. SOAP.
Server Access The REST of the Story David Cleary
Building RESTful Interfaces
SOAP.
SOAP Quang Vinh Pham Simon De Baets Université Libre de Bruxelles1.
Hypertext Transfer Protocol Kyle Roth Mark Hoover.
Web Servers How do our requests for resources on the Internet get handled? Can they be located anywhere? Global?
1 The World Wide Web Architectural Overview Static Web Documents Dynamic Web Documents HTTP – The HyperText Transfer Protocol Performance Enhancements.
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
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.
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.
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.
UNIT-V The MVC architecture and Struts Framework.
PerfSONAR Client Construction February 11 th 2010, APAN 29 – perfSONAR Workshop Jeff Boote, Assistant Director R&D.
A Scalable Application Architecture for composing News Portals on the Internet Serpil TOK, Zeki BAYRAM. Eastern MediterraneanUniversity Famagusta Famagusta.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
Sistem Jaringan dan Komunikasi Data #9. DNS The Internet Directory Service  the Domain Name Service (DNS) provides mapping between host name & IP address.
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
Copyright © Orbeon, Inc. All rights reserved. Erik Bruchez Applications of XML Pipelines XML Prague, June 16 th, 2007.
Web HTTP Hypertext Transfer Protocol. Web Terminology ◘Message: The basic unit of HTTP communication, consisting of structured sequence of octets matching.
Open Data Protocol * Han Wang 11/30/2012 *
XML Web Services Architecture Siddharth Ruchandani CS 6362 – SW Architecture & Design Summer /11/05.
Distributed Programming CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Seminar on Service Oriented Architecture Principles of REST.
1 Web Services Web and Database Management System.
Web Technologies Interactive Responsiveness Function Hypertext Web E-Publishing Simple Response Web Fill-in Forms Object Web « Full-Blown » Client/Server.
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.
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.
Representational State Transfer (REST). What is REST? Network Architectural style Overview: –Resources are defined and addressed –Transmits domain-specific.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
CS 6401 The World Wide Web Outline Background Structure Protocols.
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.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
Week 11: Application Layer 1 Web and HTTP r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file,… r Web page consists.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
SOAP, Web Service, WSDL Week 14 Web site:
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.
WWW and HTTP King Fahd University of Petroleum & Minerals
RESTful Sevices Distributed Objects Presented by: Shivank Malik
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.
z/Ware 2.0 Technical Overview
REST- Representational State Transfer Enn Õunapuu
Node.js Express Web Services
AJAX and REST.
Hypertext Transport Protocol
Representational State Transfer
Testing REST IPA using POSTMAN
WEB API.
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
$, $$, $$$ API testing Edition
Serpil TOK, Zeki BAYRAM. Eastern MediterraneanUniversity Famagusta
REST APIs Maxwell Furman Department of MIS Fox School of Business
WEB SERVICES From Chapter 19, Distributed Systems
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Designing and Implementing Web Data Services in Perl Michael McClennen

Server Data Store Client Request Response

What is "REST" ? REST is a set of architectural principles for the World Wide Web Developed by Roy Fielding, one of the Web's principal architects Stands for "REpresentational State Transfer" No consensus about exactly what it means in practice

REST: original principles Separation of client and server by a uniform interface Intermediate servers (i.e. proxies or caches) may be interposed arbitrarily All client-server interactions are stateless Data is composed of resources, each identified by a URI Server sends a representation of a resource Clients can manipulate the resource by means of the representation Representations are self-describing Client state transitions depend upon information embedded in representations (HATEOAS)

REST: in practice One protocol layer, generally HTTP no extra layers (such as SOAP) on top of it headers and status codes are used as designed Resources are identified by URIs individual resources all resources matching particular criteria Client-server interactions are stateless with the possible exception of authentication

Web Data Service (API) Data Store Client Server HTTP Request Query Result Operation Result HTTP Response HTTP Response

Web Data Service (API) Parse HTTP requests Validate parameters Talk to the backend data store Assemble representations of data Serialize representations in JSON, XML, … Set HTTP response headers Generate appropriate error messages Provide documentation about itself

What makes a good Web Data Service, from the point of view of the USER?

Well designed Well documented Flexible Consistent Responsive

Example: Wikipedia API http://en.wikipedia.org/w/api.php?action=query&list=allpages&apfrom=Perl&aplimit=50&format=json “ List 50 pages whose title starts with ‘Perl’, in JSON format ”

Example: Wikipedia API http://en.wikipedia.org/w/api.php? Base URL action=query Specify type of operation list=allpages Specify operation apfrom=Perl Query parameter aplimit=50 Specify size of result set format=json Specify result format Execute

Example: Wikipedia API http://en.wikipedia.org/w/api.php? Base URL action=query Specify type of operation list=allpages Specify operation apfrom=Perl Query parameter aplimit=50 Specify size of result set format=xml Specify result format Execute

Example: Wikipedia API http://en.wikipedia.org/w/api.php? Base URL action=query Specify type of operation list=allpages Specify operation apfrom=Perl Query parameter aplimit=5 Specify size of result set format=xml Specify result format Execute

Example: Wikipedia API http://en.wikipedia.org/w/api.php? Base URL action=query Specify type of operation list=foobar Specify operation apfrom=Perl Query parameter aplimit=5 Specify size of result set format=xml Specify result format Execute

Example: Wikipedia API http://en.wikipedia.org/w/api.php? Base URL action=query Specify type of operation list=foobar Specify operation apfrom=Perl Query parameter aplimit=5 Specify size of result set format=json Specify result format Execute

Example: Wikipedia API http://en.wikipedia.org/w/api.php? Base URL action=query Specify type of operation list=allpages Specify operation apfrom=Perl Query parameter aplimit=5 Specify size of result set format=json Specify result format foo=bar *Bad parameter* Execute

Example: Wikipedia API http://en.wikipedia.org/w/api.php Base URL only Execute

Example: Google Feed API https://ajax.googleapis.com/ajax/services/feed/find?v=1.0&q=Perl “ List all feeds whose title contains ‘Perl’ ”

Example: Google Feed API https://ajax.googleapis.com/ajax/services/ Base URL feed/find? Specify operation q=Perl Query parameter v=1.0 Protocol version Execute

Example: Google Feed API https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://www.perl.com/pub/atom.xml&num=10 “ Show the most recent 10 entries from the feed http://www.perl.com/pub/atom.xml ”

Example: Google Feed API https://ajax.googleapis.com/ajax/services/ Base URL feed/load? Specify operation q=http://www.perl.com/pub/atom.xml Query parameter v=1.0 Protocol version num=10 Size of result set Execute

Example: Google Feed API https://ajax.googleapis.com/ajax/services/ Base URL feed/load? Specify operation q=http://www.perl.com/pub/atom.xml Query parameter v=1.0 Protocol version num=NOMNOMNOM * bad value * Execute

Example: Google Feed API https://ajax.googleapis.com/ajax/services/ Base URL feed/load? Specify operation q=http://www.perl.com/pub/atom.xml Query parameter v=1.0 Protocol version numm=10 * bad parameter * Execute

Example: Google Feed API https://ajax.googleapis.com/ajax/services/ Base URL feed/load? Specify operation q=http://www.perl.com/pub/atom.xml Query parameter * missing version * Execute

Example: Google Feed API https://ajax.googleapis.com/ajax/services/ Base URL Execute

Example: Google Feed API Documentation is at: http://developers.google.com/feed/v1/jsondevguide Execute

What makes a good Web Data Service CODEBASE, From the point of view of the programmer?

Easy to implement Easy to document Easy to maintain Low overhead

Web Data Service (API) Parse HTTP requests Validate parameters Talk to the backend data store Assemble representations of data Serialize representations in JSON, XML, … Set HTTP response headers Generate appropriate error messages Provide documentation about itself

Basic data service procedure Parse URL Determine operation and result format Validate and clean the parameter values Get data from the backend (using param. vals.) Serialize the data in the selected format Set HTTP response headers appropriately If anything goes wrong, generate an error response

Introducing Web::DataService On CPAN as Web::DataService Built on top of Dancer You define operations, parameter rules, output blocks, and it handles the rest Complete enough for real use Documentation still incomplete Needs collaborators, testers, users

Important early decisions Which framework to use How to validate parameter values How to organize your parameter space How to handle output formats How to implement the response procedure How to handle versioning How to report errors How to handle documentation

Decisions that can wait Which HTTP server to use Which backend framework to use Strategies for Caching and other performance enhancements

Plan for these from the start: Multiple output formats Multiple output vocabularies Multiple protocol versions Auto-generated documentation

Decision 1: which framework? Dancer 1 Dancer 2 Mojolicious Web::DataService

Decision 2: parameter values How will the parameter values be validated and cleaned? Recommendation: use HTTP::Validate

define_ruleset('1.1:taxa:specifier' => { param => 'name', valid => \&TaxonData::validNameSpec, alias => 'taxon_name' }, "Return information about the most fundamental taxonomic name", "matching this string. The C<%> and C<_> characters may be used", "as wildcards.", { param => 'id', valid => POS_VALUE, alias => 'taxon_id' }, "Return information about the taxonomic name corresponding to this", "identifier.", { at_most_one => ['name', 'id'] } "You may not specify both C<name> and C<id> in the same query.");

Decision 2: parameter values How will the parameter values be validated and cleaned? Recommendation: use HTTP::Validate

Decision 3: parameter space How will users specify which operation to do? http://exmpl.com/service/some/thing ? … http://exmpl.com/service ? op=something & …

Decision 4: output formats How will users specify the output format? http://exmpl.com/service/something.json ? … http://exmpl.com/service ? … & format=json … Recommendation: separate the definition of output fields from output formats

$ds->define_block('1.1:taxa:basic' => { output => 'taxon_no', dwc_name => 'taxonID', com_name => ’oid' }, "A positive integer that uniquely identifies this taxonomic name", { output => 'record_type', com_name => 'typ', com_value => ’txn', dwc_value => 'Taxon', value => 'taxon' }, "The type of this record. By vocabulary:", "=over", "=item pbdb", "taxon", "=item com", "txn", "=item dwc", "Taxon", "=back", { set => 'rank', if_vocab => 'pbdb,dwc', lookup => \%RANK_STRING }, { output => 'rank', dwc_name => 'taxonRank', com_name => 'rnk' }, "The rank of this taxon, ranging from subspecies up to kingdom", { output => 'taxon_name', dwc_name => 'scientificName', com_name => 'nam' }, "The scientific name of this taxon", { output => 'common_name', dwc_name => 'vernacularName', com_name => 'nm2' }, "The common (vernacular) name of this taxon, if any", { set => 'attribution', if_field => 'a_al1', from_record => 1, code => \&generateAttribution }, … ); x x x x x x x x x x

Web::DataService provides: Web::DataService::Plugin::JSON.pm Web::DataService::Plugin::XML.pm Web::DataService::Plugin::Text.pm you can add your own Output is delegated to the appropriate module based on the selected format

Decision 4: output formats How will users specify the output format? http://exmpl.com/service/something.json ? … http://exmpl.com/service ? … & format=json … Recommendation: separate the definition of output fields from output formats

Decision 5: procedure How will you handle the basic request-response procedure? Recommendation: specify a set of attributes for each operation, and use a single body of code to handle operation execution

$ds->define_path({ path => 'taxa', class => 'TaxonData', output => '1.1:taxa:basic', doc_title => 'Taxonomic names' }); path => 'taxa/single', allow_format => 'json,csv,tsv,txt,xml', allow_vocab => 'com,pbdb,dwc', method => 'get', doc_title => 'Single taxon' }); path => 'taxa/list', method => 'list', doc_title => 'Lists of taxa' });

Decision 5: procedure How will you handle the basic request-response procedure? Recommendation: specify a set of attributes for each operation, and use a single body of code to handle operation execution

Decision 6: versioning How will users specify which protocol version? http://exmpl.com/service1.0/some/thing ? … Recommendation: make your users specify a version from the very beginning

Decision 7: error reporting Recommendation: report errors in JSON if that format was selected Recommendation: use the HTTP result codes 400 Bad request 404 Not found 415 Unrecognized media type 500 Server error Recommendation: if your code throws an exception, report a generic message

Decision 8: documentation Recommendation: auto-generate documentation as much as possible Recommendation: a request using the base URL with no parameters should return the main documentation page

Other recommendations Recommendation: know the HTTP protocol Status codes (400, 404, 500, 301, etc.) CORS ("Access-Control-Allow-Origin") Cache-Control Content-Type

Final example The Paleobiology Database Navigator http://paleobiodb.org/navigator Based on the Paleobiology Database API http://paleobiodb.org/data1.1/

Call for collaboration Please let me know if you are interested in: Using Web::DataService Testing Web::DataService Helping to further develop Web::DataService mmcclenn@geology.wisc.edu