CS 498RK FALL RESTFUL APIs

Similar documents
Controller/server communication

Controller/server communication

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

RKN 2015 Application Layer Short Summary

NODE.JS MOCK TEST NODE.JS MOCK TEST I

Networking & The Web. HCID 520 User Interface Software & Technology

Web Application Development

SAP API Management Unit 4.4: Closer look at API Owner Policy Designer PUBLIC

Networking & The Web. HCID 520 User Interface Software & Technology

LEARN HOW TO USE CA PPM REST API in 2 Minutes!

Microservices with Node.js


CSCE 120: Learning To Code

STARCOUNTER. Technical Overview

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

Develop Mobile Front Ends Using Mobile Application Framework A - 2

Lesson 14 SOA with REST (Part I)

Comet and WebSocket Web Applications How to Scale Server-Side Event-Driven Scenarios

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

Homework 8: Ajax, JSON and Responsive Design Travel and Entertainment Search (Bootstrap/Angular/AJAX/JSON/jQuery /Cloud Exercise)

CNIT 129S: Securing Web Applications. Ch 3: Web Application Technologies


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

AngularJS Fundamentals

Ajax- XMLHttpResponse. Returns a value such as ArrayBuffer, Blob, Document, JavaScript object, or a DOMString, based on the value of

PS/2 Web Services

NODE.JS SERVER SIDE JAVASCRIPT. Introduc)on Node.js

Backend Development. SWE 432, Fall Web Application Development

JavaScript Specialist v2.0 Exam 1D0-735

Jinx Malware 2.0 We know it s big, we measured it! Itzik Kotler Yoni Rom

Module 6 Node.js and Socket.IO

CORS. Константин Якушев MoscowJS 14,

Yioop Full Historical Indexing In Cache Navigation. Akshat Kukreti

Drupal Frontend Performance & Scalability

Session 18. jquery - Ajax. Reference. Tutorials. jquery Methods. Session 18 jquery and Ajax 10/31/ Robert Kelly,

NoSQL & Firebase. SWE 432, Fall Web Application Development

Session 11. Ajax. Reading & Reference

AWS Lambda + nodejs Hands-On Training

AngularJS AN INTRODUCTION. Introduction to the AngularJS framework

AJAX and JSON. Day 8

5.1 Registration and Configuration

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

Web Services Week 10

Server-Side JavaScript auf der JVM. Peter Doschkinow Senior Java Architect

RESTful Web Services. 20-Jan Gordon Dickens Chariot Solutions

Future Web App Technologies

User Interaction: jquery

AWS Lambda in (a bit of) theory and in action. Adam Smolnik

AJAX: The Basics CISC 282 November 22, 2017

Developing a Web Server Platform with SAPI support for AJAX RPC using JSON

MASTERS COURSE IN FULL STACK WEB APPLICATION DEVELOPMENT W W W. W E B S T A C K A C A D E M Y. C O M

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

IERG 4080 Building Scalable Internet-based Services

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

RESTful API Design APIs your consumers will love

Integration Test Plan

AJAX: The Basics CISC 282 March 25, 2014

Send me up to 5 good questions in your opinion, I ll use top ones Via direct message at slack. Can be a group effort. Try to add some explanation.

RESTFUL WEB SERVICES - INTERVIEW QUESTIONS

Oracle Transportation Management. REST API Getting Started Guide Release Part No. E

CORS Attacks. Author: Milad Khoshdel Blog: P a g e. CORS Attacks

SharePoint 2013 CRUD on List Items Using REST Services & jquery

Project Avatar: Server Side JavaScript on the JVM GeeCon - May David Software Evangelist - Oracle

REST in a Nutshell: A Mini Guide for Python Developers

Web Robots Platform. Web Robots Chrome Extension. Web Robots Portal. Web Robots Cloud

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

Composer Help. Web Request Common Block

Browser code isolation

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

Table of Contents 1.1. Introduction 1.2. General HTTP Handling 1.3. HTTP Interface 1.4. Databases To-Endpoint Management 1.4.

Jquery.ajax Call Returns Status Code Of 200 But Fires Jquery Error

Installation Guide. Sitecore Federated Experience Manager. Installation & Configuration Guide

Copyright Descriptor Systems, Course materials may not be reproduced in whole or in part without prior written consent of Joel Barnum

Active Endpoints. ActiveVOS Platform Architecture Active Endpoints

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

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

INDEX SYMBOLS See also

RESTful Services. Distributed Enabling Platform

Web 2.0 and Security

Index. C CakePHP framework, 232 Cascading Style Sheets (CSS)

AJAX: Introduction CISC 282 November 27, 2018

Full Stack Web Developer Nanodegree Syllabus

6 th October 2018 Milan

LOG8430: Architecture logicielle et conception avancée

How A Website Works. - Shobha

REST Services. Zaenal Akbar

Assignment: Seminole Movie Connection

Asema IoT Central Integration and migration. English

Building Offline Mobile Apps with Oracle JET and MCS

A Scalable Event Dispatching Library for Linux Network Servers

DESIGN AND IMPLEMENTATION OF SAGE DISPLAY CONTROLLER PROJECT

DECOUPLING PATTERNS, SERVICES AND CREATING AN ENTERPRISE LEVEL EDITORIAL EXPERIENCE

Developing ASP.NET MVC Web Applications (486)

Node.js. Node.js Overview. CS144: Web Applications

Enterprise Web Development

PROCE55 Mobile: Web API App. Web API.

Creating a REST API which exposes an existing SOAP Service with IBM API Management

THE NEW ERA OF WEB DEVELOPMENT. qooxdoo. Andreas Ecker, Derrell Lipman

REST AND AJAX. Introduction. Module 13

Large-Scale Web Applications

Transcription:

CS 498RK FALL 2017 RESTFUL APIs

Designing Restful Apis blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/ www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

Resources Apply Verbs to Nouns Http Methods

GET Get a representation of resource Verbs DELETE Destroy resource POST Create a new resource based on the given representation PUT Replace resource state with the one described in the given representation HEAD Get the headers that would be sent with a representation, but not the representation itself OPTIONS Discover which HTTP methods this resource responds to PATCH Modify part of the state of this resource based on the given representation

COLLECTIONS <VERB> http://example.com/users GET Return all the objects in the collection POST Create a new entry in the collection; automatically assign new URI and return it PUT and DELETE not generally used

ELEMENTS <VERB> http://example.com/users/12345 GET Return the specific object in collection PUT Replace object with another one DELETE Delete element POST not generally used

USING PARAMETERS <VERB> http://example.com/users? where={"num_posts":{"$gt":100}}} Json-encoded filter other parameters can be used to select fields, sort, etc. parameters can also be URL-encoded

ONE-TO-FEW How would you access the address of a particular user?

ONE-TO-FEW GET http://example.com/users/12345 embedded in Json

ONE-TO-MANY How would you access the posts of a particular user?

ONE-TO-MANY GET http://example.com/users/12345 GET http://example.com/posts? where={"_id":{"$in":[...]}} not HATEOS

PAGINATION GET http://example.com/users? offset=60&limit=20 offset ith object limit number of returned objects can also use Link header to specify next, prev, first, last URLs

CHECKLIST: BASICS Use nouns but no verbs Use plural nouns Don t expose irrelevant nouns GET method and query parameters should not alter the state

CHECKLIST: BASICS Use parameters to filter, sort, and select fields from collections Use offset and limit parameters to paginate results

CHECKLIST: RELATIONS if a relation is usually requested alongside the resource, embed the relation's representation within the output representation of the resource if a relation can exist independently, include an identifier for it within the output representation of the resource

CHECKLIST: FORMATS Content-Type and Accept headers Can also explicitly declare format in URL

CHECKLIST: INTERFACING WITH CONSUMERS Handle Errors with HTTP status codes An API is only as good as its documentation Self-documenting APIs

HTTP/1.1 200 OK Content-Type: application/xml Content-Length:... <?xml version="1.0"?> <account> <account_number>12345</account_number> <balance currency="usd">100.00</balance> <link rel="deposit" href="https://bank.example.com/accounts/12345/deposit" /> <link rel="withdraw" href="https://bank.example.com/accounts/12345/withdraw" /> <link rel="transfer" href="https://bank.example.com/accounts/12345/transfer" /> <link rel="close" href="https://bank.example.com/accounts/12345/close" /> </account>

CHECKLIST: HATEOS? Hypermedia as the Engine of Application State navigate the Web by following links should the API consumer create links or should they be provided? Better to assume the user has access to the documentation & include resource identifiers in the output representation Advantages: stored data and data over the network minimized, ids more stable than URLs

CHECKLIST: PREVENT ABUSE Rate Limiting Authentication

CHECKLIST: CACHING ETag contains a hash or checksum of the representation validated against client s If- None-Match. If match, the API returns a 304 Not Modified status code Last-Modified contains a timestamp which is validated against If-Modified-Since

Dealing with Same-Origin Policy

application lives on llama.com and you want to pull data from www.alpaca.com var xhr = new XMLHttpRequest(); xhr.open('get', 'http://www.alpaca.com/hello.json'); xhr.onload = function(e) { var data = JSON.parse(this.response);... } xhr.send(); What happens?

application lives on llama.com and you want to pull data from www.alpaca.com var xhr = new XMLHttpRequest(); xhr.open('get', 'http://www.alpaca.com/hello.json'); xhr.onload = function(e) { var data = JSON.parse(this.response);... } xhr.send(); origin mismatch error!

SAME-ORIGIN POLICY implemented by all major browsers only web pages that have the same origin can access each other s data origin = protocol, domain name, port (some browsers) does not apply to <img> and <script>

SAME-ORIGIN POLICY but applies to AJAX requests "Cross-domain" AJAX requests are forbidden by default because of their ability to perform advanced requests POST, PUT, DELETE and other types of HTTP requests, along with specifying custom HTTP headers introduce many security issues as described in cross-site scripting

CROSS-ORIGIN RESOURCE SHARING new html5 feature CORS allows web applications on one domain to make cross domain AJAX requests to another domain. Access-Control-Allow-Origin header in HTTP responses more freedom than purely same-origin requests, but more secure than allowing all cross-origin requests http://www.html5rocks.com/en/tutorials/file/xhr2/

CORS WORKAROUND // browser sends the following request header Origin: http://llama.com // server response: give access to llama.com Access-Control-Allow-Origin: http://llama.com // give access to all domains Access-Control-Allow-Origin: *

Access-Control-Allow-Origin: * useful when a page or API is intended to be accessible to everyone, including any code on any site freely-available web fonts Google Fonts

CORS IN MP3 //Allow CORS so that backend and frontend could be put on different servers var allowcrossdomain = function(req, res, next) { res.header("access-control-allow-origin", "*"); res.header("access-control-allow-headers", "X-Requested- With, X-HTTP-Method-Override, Content-Type, Accept"); }; next(); app.use(allowcrossdomain);

AJAX CALLS If the server endpoint has enabled CORS, making the cross-origin request is no different than a normal XMLHttpRequest request

Node and Express

SERVER-SIDE JAVASCRIPT Client Server MY BLOG This is my first post. API DATABASE ADD POST React Express, Node

NODE Node.js is a platform built on Chrome s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, nonblocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices nodejs.org

NON-BLOCKING Asychronous I/O operations are slow non-blocking while one process is waiting for I/ O, let another process make use of CPU

TRADITIONAL SERVERS Apache, IIS servers serve several clients at the same time: how? multi-process or multi-threaded each connection results in the creation of a dedicated child process/thread parent process/main thread remains available, listening for new connections

EVENT-DRIVEN CONCURRENCY Node, nginx, Twisted, EventMachine everything runs in one process, one thread a event is emitted and the appropriate callback for that event is invoked Once an event is treated, the process is ready to treat another event www.teenycloud.com/blog/2013/11/30/node-event-driven-programming/

www.teenycloud.com/blog/2013/11/30/node-event-driven-programming/

THE EVENT-LOOP all the events are processed by event-loop queue event-loop fetches next event to process and dispatches the corresponding handler anyone blocking the event-loop will prevent the other events from being processed single-threaded: DO NOT BLOCK THE EVENT LOOP Node API is non-blocking (with the exception of some file system operations which come in two flavors: asynchronous and synchronous) www.w3.org/tr/2004/rec-webarch-20041215/

JAVASCRIPT AND I/O JavaScript was designed for being used inside a browser; missing basic I/O libraries (such as file operations) Node: Javascript + I/O API could make I/O natively non-blocking in Node www.w3.org/tr/2004/rec-webarch-20041215/

EXPRESS Web application framework built on top of Node provides scaffolding: a thin layer of fundamental web application features minimal, flexible serve simple pages, APIs, etc. expressjs.com

NEXT CLASS: MIDTERM REVIEW courses.engr.illinois.edu/cs498rk1/