Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RESTful API @ Front-End Developers Taiwan 2014-04-23

Poga Po
April 24, 2014

RESTful API @ Front-End Developers Taiwan 2014-04-23

Poga Po

April 24, 2014
Tweet

More Decks by Poga Po

Other Decks in Programming

Transcript

  1. REpresentational State Transfer • Resource and Representation • Manipulation through

    Representation • Self-Descriptive • Links between Resources
  2. gov.tw/投票紀錄/張慶忠/ /政府/投票紀錄/張慶忠/ { 沒有投票: 7, 贊成: 79, 反對: 271, 紀錄:

    [ { 表決內容: 交通資訊雲端blahblah, 個⼈人投票: 贊成, 表決結果: 通過, ⽇日期: 2014-01-27 }, … ] } Resource Entry
  3. Q?

  4. Q?

  5. gov.tw/legislators/張慶忠/ { 姓名: “張慶忠” 黨籍: “KMT”, 選區: “新北市”, 參與院會紀錄: {…},

    聯絡⽅方式: { TEL: ‘…’, 地址: ‘…’ }, 經歷: [ … ] } 投票紀錄? 財產紀錄? 選舉得票紀錄? GET
  6. gov.tw/legislators/張慶忠/ { 姓名: “張慶忠” 黨籍: “KMT”, 選區: “新北市”, 參與院會紀錄: {…},

    聯絡⽅方式: { TEL: ‘…’, 地址: ‘…’ }, 經歷: [ … ], 投票紀錄: “/投票紀錄/張慶忠/”, 財產紀錄: “/財產紀錄/張慶忠/” }
  7. HATEOAS • Hypermedia as the Engine of Application State •

    直接在 Representation 中建⽴立 Resource 之間的連 結,⽽而不是透過外部⽂文件 • Decoupling Server and Client.
  8. gov.tw/legislators/張慶忠/ { 姓名: “張慶忠” 黨籍: “KMT”, 選區: “新北市”, 參與院會紀錄: {…},

    聯絡⽅方式: { TEL: ‘…’, 地址: ‘…’ }, 經歷: [ … ], 投票紀錄: “/投票紀錄/張慶忠/”, 財產紀錄: “/財產紀錄/張慶忠/”, 罷免: “/recalls/張慶忠” }
  9. Q?

  10. PgREST is… • … a JSON document store • …

    running inside PostgreSQL • … working with existing relational data • … capable of loading Node.js modules • … compatible with MongoLab’s REST API • … compatible with Firebase API (new)
  11. From Data… 姓名 電話 黨籍 0 張慶忠 02-123-4567 KMT 1

    林鴻池 02-123-4567 KMT 2 ⺩王⾦金平 02-123-4567 KMT 3 柯建銘 02-123-4567 DPP Table: legislators
  12. … to REST API http://localhost:3000/collections/legislators [ { id: 0, 姓名:

    柯建銘 … }, { … }, … ] > pgrest —db mydb