Web-Services and RESTful APIs

Slides:



Advertisements
Similar presentations
Pierre-Johan CHARTRE Java EE - JAX-RS - Pierre-Johan CHARTRE
Advertisements

REST - Representational State Transfer
REST Vs. SOAP.
Building and using REST information services Rion Dooley.
Introduction to Web Services
A REST-ful Web Services Approach to Library Federated Search using SRU Kevin Reiss Rutgers-Newark Law Library CALI 2005 – June 11th.
Server Access The REST of the Story David Cleary
REST (Representational State Transfer)
Overview of Twitter API Nathan Liu. Twitter API Essentials Twitter API is a Representational State Transfer(REST) style web services exposed over HTTP(S).
Hypertext Transfer PROTOCOL ----HTTP Sen Wang CSE5232 Network Programming.
Introduction to Computing Using Python CSC Winter 2013 Week 8: WWW and Search  World Wide Web  Python Modules for WWW  Web Crawling  Thursday:
HTTP By: Becky Fultz, Joe Flager, Katie Huston, Tom Packard, Allison Wilsey.
Web Servers How do our requests for resources on the Internet get handled? Can they be located anywhere? Global?
06 | Implementing Web APIs Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
1 Web Servers (IIS and Apache) Outline 9.1 Introduction 9.2 HTTP Request Types 9.3 System Architecture 9.4 Client-Side Scripting versus Server-Side Scripting.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
TCP/IP Protocols Dr. Sharon Hall Perkins Applications World Wide Web(HTTP) Presented by.
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 Seminar on Service Oriented Architecture Principles of REST.
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.
2007cs Servers on the Web. The World-Wide Web 2007 cs CSS JS HTML Server Browser JS CSS HTML Transfer of resources using HTTP.
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.
Service Oriented Programming 1 Javier Espinosa, PhD
RESTful Web Services What is RESTful?
RESTful Web Services A MIDAS MISSION PRESENTATION APRIL 29, 2015.
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
REST API Design. Application API API = Application Programming Interface APIs expose functionality of an application or service that exists independently.
National College of Science & Information Technology.
Web Development. Agenda Web History Network Architecture Types of Server The languages of the web Protocols API 2.
Tiny http client and server
The Client-Server Model
API (Application Program Interface)
Hypertext Transfer Protocol
Content from Python Docs.
Better RESTFul API – Best Practices
Web Development Web Servers.
API Security Auditing Be Aware,Be Safe
WEB SERVICES.
REST: Web Services Abel Sanchez.
REST- Representational State Transfer Enn Õunapuu
Node.js Express Web Services
C++ Tango REST API implementation
An introduction to REST for SharePoint 2013
Hypertext Transport Protocol
What is REST API ? A REST (Representational State Transfer) Server simply provides access to resources and the REST client accesses and presents the.
Some bits on how it works
Introduction Web Environments
Applied Cyber Infrastructure Concepts Fall 2017
Ashish Pandit IT Architect, Middleware & Integration Services
WEB API.
HyperText Transfer Protocol
Creating a Distributed System with Remote Procedure Calls and Web Services Ch.5 B.Ramamurthy 2/17/2019 B.Ramamurthy.
REST APIs Maxwell Furman Department of MIS Fox School of Business
Python and REST Kevin Hibma.
CS4961 Software Design Laboratory Understand Aquila Backend
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
Project BCHB697.
NoSQL & Document Stores
WCF Data Services and Silverlight
.NET Framework V3.5+ & RESTful web services
Chengyu Sun California State University, Los Angeles
REST API Design Borrowed heavily from:
Presentation transcript:

Web-Services and RESTful APIs BCHB697

Outline Web-services RESTful web-services Use of RESTful APIs from Python CouchDB, UniProt BCHB697 - Edwards

Web-services Provide computers information or computed values over the network Internet as network (global, IP) HyperText Transfer Protocol (HTTP, HTTPS) Machine-readable responses (XML, JSON) Remote "Function Call": Send data (parameters), get data back Uses the same infrastructure that supports web browsers and facebook, gmail, etc… BCHB697 - Edwards

Web-services http://hoyataxa.georgetown.edu:8080/taxa?taxid=9606&format=XML protocol (http,https) computer name resource port # (80 if omitted) resource/request parameters http://hoyataxa.georgetown.edu/taxa/9606.xml protocol (http,https) computer name resource resource/request parameters BCHB524 - Edwards

HyperText Transfer Protocol (HTTP) Uniform Resource Locator (URL): Protocol; machine; port; resource; parameters For the interactive web, two main request types (methods): GET – everything is encoded in the URL POST – URL plus extra data. GET requests (URLs) can be bookmarked POST requests for web-form submissions BCHB697 - Edwards

authority / data-provider RESTful web-services Web-service APIs are often used to provide the instances of a logical data-model to client applications REST: Representational State Transfer RESTful web-services associate URIs with data-model entities: Uniform Resource Identifier http://hoyataxa.georgetown.edu/taxa/9606 protocol (http,https) authority / data-provider entity identifier BCHB697 - Edwards

authority / data-provider RESTful web-services RESTful web-services associate URIs with data-model entities: Notice how well this maps to database, table, and row This web-service returns everything about taxonomy id 9606 in XML or JSON format. http://hoyataxa.georgetown.edu/taxa/9606 protocol (http,https) authority / data-provider entity identifier BCHB697 - Edwards

authority / data-provider RESTful web-services RESTful web-services associate URIs with data-model entities: Notice how well this maps to database, table, and row This web-service returns everything about taxonomy id 9606 in XML or JSON format. http://hoyataxa.georgetown.edu/taxa/9606 protocol (http,https) authority / data-provider entity identifier BCHB697 - Edwards

Examples of RESTful resource URIs UniProt https://www.uniprot.org/uniprot/P25911 GlyTouCan https://glytoucan.org/Structures/Glycans/G00028MO NCBI https://www.ncbi.nlm.nih.gov/gene/54923 These URIs are easily constructed and quite transparent Access using HTTP GET; safe & read only BCHB697 - Edwards

RESTful Web-Services Unique URI to reference every resource in your API Omit identifier for summary or list Use parameters for collections or subsets GET requests for URIs and simple parameters http://hoyataxa.georgetown.edu/taxa/9606 http://hoyataxa.georgetown.edu/taxa http://hoyataxa.georgetown.edu/taxa?rank=species BCHB697 - Edwards

RESTful Web-Services HTTP request types: Create: POST to entity URI GET – retrieve a specific resource (idempotent) PUT – update a specific resource (idempotent) DELETE – delete a specific resource (idempotent) POST – create/retrieve/update/delete (CRUD) one or more resources Create: POST to entity URI Retrieve: GET instance URI Update: POST or PUT instance URI Delete: POST or DELETE instance URI BCHB697 - Edwards

RESTful Web-Services HTTP request body: HTTP return codes: … for PUT, DELETE, POST May be empty or JSON/XML GET style parameters can also be used HTTP return codes: 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 500 Internal Server Error BCHB697 - Edwards

RESTful Web-Services Takes advantage of existing web-based infrastructure technologies Caching Load balancing Proxying Authentication BCHB697 - Edwards

Example Web-Services UniProt: GlyTouCan: GlyGen: CouchDB https://www.ebi.ac.uk/proteins/api GlyTouCan: https://api.glytoucan.org GlyGen: http://api.glygen.org/test/glycan.html CouchDB http://docs.couchdb.org/en/latest/api/index.html http://docs.couchdb.org/en/latest/api/database/find.html BCHB697 - Edwards

CouchDB RESTful GET requests: /<db>/_all_docs, /<db>/<id> from urllib import urlopen from json import loads baseurl = 'https://edwardslab.bmcb.georgetown.edu/couchdb/' request = 'uniprot/_all_docs' response = loads(urlopen(baseurl+request).read()) for r in response['rows']: eid = r['id'] entry = loads(urlopen(baseurl+'uniprot/'+eid).read()) print entry['accession'] BCHB697 - Edwards

CouchDB RESTful GET requests: /<db>/_all_docs, /<db>/<id> from couchws import * request = 'uniprot/_all_docs' response = couch_webservice_request(request) for r in response['rows']: eid = r['id'] entry = couch_webservice_request('uniprot/'+eid) print entry['accession'] BCHB697 - Edwards

CouchDB For GET requests, urllib is fine, but otherwise… import sys, json from couchws import * print "Get uniprot entry by accession" payload = {"selector": { "accession": "A0A001" }} print json.dumps(payload,indent=2) request = '/uniprot/_find' response = couch_webservice_request(request,payload,method='POST') print json.dumps(response,indent=2) print "Get uniprot entry by _id" id = response["docs"][0]["_id"] request = '/uniprot/'+id response = couch_webservice_request(request) BCHB697 - Edwards

CouchDB Use urllib2 (or another modern library) to handle PUT and DELETE requests and/or authentication Use a module to hide the ugly details! def couch_webservice_request(request, payload={}, method='GET', username=None, password=None) BCHB697 - Edwards

CouchDB For GET requests, urllib is fine, but otherwise… import sys, json from couchws import * db = sys.argv[1] request = db print "Create database",db response = couch_webservice_request(request,method='PUT', username='admin', password='admin') print json.dumps(response,indent=2) print "Get database status" response = couch_webservice_request(request) print "Delete database",db response = couch_webservice_request(request, method='DELETE', BCHB697 - Edwards

Load CouchDB from UniProt import sys, json from couchws import * db = sys.argv[1] response = couch_webservice_request(db, method='PUT', username='admin', password='admin') print json.dumps(response,indent=2) payload = dict(offset=0, size=1000, taxid=int(sys.argv[2])) response = uniprot_webservice_request("/proteins",payload) print len(response), "documents from uniprot" all_docs = {'docs': response} request = "/"+db+"/"+"_bulk_docs" response = couch_webservice_request(request, all_docs, method='POST') BCHB697 - Edwards

Exercise Explore the uniprot, glygen, glytoucan, and couchdb web-services Implement some novel interactions with couchdb: Make sure your database names are unique use your net-id? Implement some novel interactions with uniprot, glygen, glytoucan. Can you successfully retrieve data? BCHB697 - Edwards