2014年12月13日 星期六

Introduction to REST & JSON

What is REST?

Representational State Transfer (REST) is a style of software architecture for distributed systems.

 使用 REST 為設計架構的系統我們就稱為 RESTful系統

 RESTful Web Services(或稱RESTful Web API)是以HTTP為基礎,必且有以下三個特色
  1. 所有的API或是以Resource的形式存在,例如 htttp://www.test.com/examples/12345
  2. 這個服務可以接受與返回某個MIME-TYPE,最常見的是JSON格式,也可以回傳PNG/JPG/TXT等格式。
  3. 對資源的操作會支援各種請求方法 (例如GET, POST, PUT, DELETE)

What is JSON?

JavaScript Object Notation (JSON) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate” – JSON.org


JSON
XML
Data Structure
Data Structure
No validation system
XSD
No namespaces
Has namespaces (can use multiples)
Parsing is just an eval
Fast
Security issues
Parsing requires XML document parsing using things like XPath
In JavaScript you can work with objects – runtime evaluation of types
In JavaScript you can work with strings – may require additional parsing
Security: Eval() means that if the source is not trusted anything could be put into it.
Libraries exist to make parsing safe(r)
Security: XML is text/parsing – not code execution.