Введение в rest api

22
Oleg Zinchenko [email protected] Введение в REST API Подходы к генерации API документации

Upload: oleg-zinchenko

Post on 27-Jan-2015

140 views

Category:

Technology


10 download

DESCRIPTION

Введение в REST API. подходы к генерации API документации

TRANSCRIPT

Page 1: Введение в REST API

Oleg [email protected]

Введение в REST APIПодходы к генерации API документации

Page 2: Введение в REST API

О себе

Symfony разработчик с 2009 года

TeamLead в Exercise.com

Продвигаю Symfony2 в массы

https://twitter.com/1cdecoder

https://github.com/cystbear

http://cystbear.tumblr.com/

Page 3: Введение в REST API

Oleg Zinchenko

Exercise.com

Программы

Питание

Упражнения

Видео

Советы тренера

Френды, лайки

Page 4: Введение в REST API

Oleg Zinchenko

REST

REpresentational State Transfer

Over HTTP

State-less

Кеширование

Передача состояний

Page 5: Введение в REST API

Oleg Zinchenko

REST

ACTIONS (HTTP METHODS)

GETPOSTPUT/PATCHDELETE

Page 6: Введение в REST API

Oleg Zinchenko

REST

RESTful web API

forbidden/api/v1/orders/12/deleteGET/api/v1/orders/12DELETE/api/v1/orders/12PUT/api/v1/orders/12GET/api/v1/ordersPOST/api/v1/ordersGET

Page 7: Введение в REST API

Oleg Zinchenko

Задача

Page 8: Введение в REST API

Oleg Zinchenko

Задача{"firstName": "Иван","lastName": "Иванов","address": {"streetAddress": "Московское ш., 101, кв.101","city": "Ленинград","postalCode": 101101

},"phoneNumbers": ["812 123-1234","916 123-4567"]

}

<person><firstName>Иван</firstName><lastName>Иванов</lastName> <address><streetAddress>Московское ш., 101, кв.101</streetAddress><city>Ленинград</city><postalCode>101101</postalCode>

</address>

<phoneNumbers><phoneNumber>812 123-1234</phoneNumber><phoneNumber>916 123-4567</phoneNumber>

</phoneNumbers></person>

Page 9: Введение в REST API

Oleg Zinchenko

Bundles

FOSRestBundleFOSRest

JMSSerializerBundle

jms/metadata

Page 10: Введение в REST API

Oleg Zinchenko

2 Kernels

AppKernel

ApiKernelРазный набор конфигов

Разный набор бандлов

Page 11: Введение в REST API

Oleg Zinchenko

authentication + authorization

authentication + authorization

Page 12: Введение в REST API

Oleg Zinchenko

Authentication

http://www.xml.com/pub/a/2003/12/17/dive.html

Page 13: Введение в REST API

Oleg Zinchenko

Serialization

Serializer mapDemo\Acme\Document\Food:

exclusion_policy: ALLproperties:

calories:expose: true

caloriesPerServing:expose: true

caloriesPerGram:expose: true

caloriesPerFluidOunce:expose: true

measurement:expose: true

servingOptions:expose: true

callback_methods:pre_serialize: [prepareMeasurement, prepareServingOptions]

Page 14: Введение в REST API

Oleg Zinchenko

Serialization

Object Handlers{

"id": "4fb1fb87944c4c0e240004de",

"slug": "minimalist-article",

"title": "Minimalist article",

"updated_at": "2012-05-15T09:45:26+0300",

"summary": "Minimalist summary",

"body": "Minimalist body",

"main_image": "http://e.com/upl/art/thum/parrot.mobile_client_medium.v1.jpg"

}

Page 15: Введение в REST API

Oleg Zinchenko

Тестирование

Behat

Buzz + aka WebApiContextScenario: /foods get list of food. Pagination supported.

Given I authorized as: "fred"

When I make "GET" request to the "/api/v1/foods"

Then the response status code should be: "200"

And the response body should be similar to JSON:

"""

[{"id":"4fb1fb8f944c4c0e24000622","slug":"bittermelon-cooked-a… }]

"""

Page 16: Введение в REST API

Oleg Zinchenko

Документация

Hippo doc

Swagger

NelmioApiDocBundle

Page 17: Введение в REST API

Oleg Zinchenko

Документация

http://api.jirafe.com/

Hippo doc

Page 18: Введение в REST API

Oleg Zinchenko

Документация

Swagger

http://swagger.wordnik.com/

apis: [{path: "/pet.{format}/{petId}",description: "Operations about pets",operations: [{httpMethod: "GET",nickname: "getPetById",responseClass: "Pet",parameters: [...]summary: "Find pet by its unique ID"notes: "Only Pets which you have permission to see will be returned",errorResponses: [...]

}]}

Page 19: Введение в REST API

Oleg Zinchenko

Документация

Swagger

http://swagger.wordnik.com/

Page 20: Введение в REST API

Oleg Zinchenko

Документация

NelmioApiDocBundle/*** This the documentation description of your method, it will appear* on a specific pane. It will read all the text until the first* annotation.** @ApiDoc(* resource=true,* description="This is a description of your API method",* filters={* {"name"="a-filter", "dataType"="integer"},* {"name"="another-filter", "dataType"="string", "pattern"="(foo|bar) ASC|DESC"}* }* )*/public function getAction(){}

https://github.com/nelmio/NelmioApiDocBundle

Page 21: Введение в REST API

Oleg Zinchenko

Документация

NelmioApiDocBundle

https://github.com/nelmio/NelmioApiDocBundle

Page 22: Введение в REST API

Oleg Zinchenko

Спасибо

Вопросы?