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

Hypermedia API (MinskJS version)

Artem Bey
March 15, 2016
70

Hypermedia API (MinskJS version)

Artem Bey

March 15, 2016
Tweet

Transcript

  1. 3

  2. http://…/resource <xml> <entity/> </xml> { entity: {…} } представление представление

    ресурс идентификатор документ картинка процесс … 8
  3. REST уровня 0 POST /api { "do": "createOrder", "params": {

    "count": 2 } } POST /api { "do": "cancelOrder", "params": { "id": "34xzfha834flksd34" } } 200 OK { "success": true, "res": { "id": "f239sdk237sdf438" } } 200 OK { "success": false, "error": { "code": 666, "message": "because fk u thats why" } } /api 10
  4. REST уровня 1 POST /users {…} 200 OK { "success":

    true, "res": { "id": "f239sdk237sdf438" } } 200 OK { "success": false, "error": { "code": 40000, "message": "not valid req" } } /users POST /users/1 {…} POST /orders {…} /users/1 /orders 11
  5. 15

  6. 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found

    402 Payment Required 409 Conflict … 17
  7. /users /orders /profile … GET POST PUT DELETE OPTIONS HEAD

    PATCH … 200 201 … 300 301 … 400 401 … 500 501 … покроют все ваши кейсы 19
  8. GET /feed 200 OK { "data": [ { "title": "...",

    "links": { "details": "http://..." } }, .... ], "links": { "self": "http://...", "first": "http://...", "prev": "http://...", "next": "http://...", "last": "http://..." } } 24 << < > >>
  9. GET /feed?min_id=100500 200 OK { "data": [ { "title": "...",

    "links": { "details": “http://..." } }, .... ], "links": { "self": "http://...", "first": "http://...", "prev": "http://...", "next": "http://...", "last": "http://..." } } 25 << < > >>
  10. GET /films/themartian 200 OK { "data": { "title": "Марсианин", "description":

    "Как Мэт Дэймон выращивал картошку на Марсе", "duration": 140, "poster": "https://s3.amazon.com/buckets/23aGd23asdsf.png" }, "links": { "self": "http://.../themartian", "booking": "http://.../themartian/bookings" } } 26
  11. OPTIONS /films/themartian/bookings 204 No Content Allow: HEAD,GET,POST,OPTIONS 27 GET /films/themartian

    200 OK { "data": { "title": "Марсианин", "description": "Как Мэт Дэймон выращивал картошку на Марсе", "duration": 140, "poster": "https://s3.amazon.com/buckets/23aGd23asdsf.png" }, "links": { "self": "http://.../themartian", "booking": "http://.../themartian/bookings" } }
  12. GET /films/themartian/bookings/1 200 OK { "data": { "count": 3, "date":

    "Tue Nov 03 2015 21:45:55 GMT+0200 (EET)", "status": "waiting" }, "links": { "self": "http://..../bookings/1", "cancel": "http://..../bookings/1/cancel", "pay": "http://.../bookings/1/pay" } } 29
  13. Некоторые приёмы • Безопасные и идемпотентные операции • Кеширование неизменяемых

    ресурсов • X- заголовки • Вендорные типы данных (application/ vnd.myapi.basket.v1+json) 36