際際滷
Submit Search
Building better APIs on rails
1 like
286 views
R
Roman Gorel
Follow
Presentation shown on #kievrb 3
Read less
Read more
1 of 50
Download now
Download to read offline
More Related Content
Building better APIs on rails
1.
Building better APIs
on Rails Roman Gorel @ kiev.rb #3
2.
亠仍 - 仆亠
于亠亞亟舒 仍亠 仆亠亞亳亠 亠仍舒仄亳 从舒从 Rack mountable engine 亠仆亠 于亠仄 仂于亠舒 亳亠亞仂 仍亳仆亠亞仂
3.
rails-api gem
亠 亠从于舒亶亳 仂, 仂 仆亠 仆亢仆仂 亟仍 API (仆舒仗亳仄亠, 亠仄仗仍亠亶) 丕从仂磳 于亠仄 仂于亠舒 丕仄亠仆舒亠 仗仂亠弍仍磳仄亠 亠
4.
丕弍亠亠仄 仆亠仆亢仆仂亠
仍 仆仂于 仗亳仍仂亢亠仆亳亶 仍 亠于ム亳 仗亳仍仂亢亠仆亳亶
5.
仂弍舒于亳仄 仂
6.
亠亶仄仗亠亶, 于亠亳亳, 仂仄舒
7.
弌弍亟仂仄亠仆 http://api.pumpkins.ua/v1/pumpkins
8.
弌弍亟仂仄亠仆 于 development
env /etc/hosts api.lvh.me pow
9.
弌从舒 从仂仆仂仍仍亠仂于
10.
亠仍舒亠仄 API 舒弍弍亠于亳舒仂亶
config/initializers/inflections.rb Api::V1::PumpkinsController API::V1::PumpkinsController
11.
仂仆仂仍仍亠
12.
舒亰仆亠 仂仄舒 亟舒仆仆?
13.
弌仂从舒舒亠仄 从仂亟
14.
舒从 仗仂仄亠仆 仗亠亟舒于仍亠仆亳亠?
15.
舒 亞亠仄仂于 亟仍
从舒仂仄亳亰舒亳亳 仗亠亟舒于仍亠仆亳 丐亠仄仗仍亠亶: rabl, jbuilder 亠亰亠仆亠: representable, acts_as_api 弌亠亳舒仍舒亶亰亠: ActiveModelSerializers
16.
仄亠仍 亠从
app/presenters/api/v1/pumpkin_presenter.rb
17.
仄亠仍 亠从
18.
仂仍亠 亞亳弍从仂亳!
19.
仂仍亠 亞亳弍从仂亳!
20.
从舒从 仆舒亠
从仂仍仍亠从亳亶? app/presenters/api/array_presenter.rb
21.
仂从仄亠仆舒亳
22.
RDoc FAIL
23.
仂从仄亠仆亳亠仄 从舒亳于仂
swagger apipie rspec_api_documentation
24.
仂从仄亠仆舒亳 亠亠亰 亠
亠 亰舒仍舒仄仍磳 从仂仆仂仍仍亠 仂亠 仗仂亟亟亠亢亳于舒 于 舒从舒仍仆仂仄 仂仂礌亳亳 仂亞仂仆磳 亠 仗亳 亞亠仆亠舒亳亳 亠仆亠 仗亳舒 从舒仄亳 舒舒于仍磳 仗亳舒 亠 :)
25.
仂从仄亠仆亳亠仄 亳亰 亠仂于
Gemfile spec/support/rspec_api_documentation.rb
26.
仂从仄亠仆亳亠仄 亳亰 亠仂于
spec/acceptance/pumpkins_spec.rb
27.
仗亳于舒亠仄 仄亠仂亟
28.
仗亳于舒亠仄 仄亠仂亟
29.
于舒 于 仂亟仆仂仄
$ rake docs:generate 仂亞仂仆磳 亠 亠仆亠亳亠 亟仂从
30.
舒仍舒亢亟舒亠仄 亠亰仍舒仂仄
31.
舒仍舒亢亟舒亠仄 亠亰仍舒仂仄
32.
亠仆亳亳从舒亳
33.
舒亰仂于舒 亠仆亳亳从舒亳
34.
舒亰仂于舒 亠仆亳亳从舒亳
35.
FAIL :(
36.
Digest Auth +
token 亠仍舒亠仄 POST /sessions 亰舒亳仂于舒仆仆仄亳 仍仂亞亳仆仂仄 亳 仗舒仂仍亠仄 仂仍舒亠仄 于 仂于亠 仂从亠仆 仗仂仍亰亠仄 仂从亠仆 于 仗仂仍亠亟ム亳 亰舒仗仂舒
37.
Digest Auth
38.
Digest Auth $
curl -v --digest -u "Roman:password" -X POST --data {} http://api.pumpkins. ua:3000/v1/sessions
39.
Token
40.
Token $ curl
-H 'Authorization: Token token="48990736263c9f573ff634a1cb66cbcd"' http://api.pumpkins.ua:3000/v1/pumpkins
41.
仂弍仍亠仄 弌仍仂亢仆舒
舒亠仆亳亳从舒亳 从亶 仂从亠仆
42.
JSON Web token
jwt.io 亠舒仍亳亰舒亳亳 仗仂亟 仄仆仂亢亠于仂 仗仍舒仂仄 仂仂舒 亳仗仂仍亰仂于舒仆亳 弌亠从ム仆仂
43.
亠仆亳亳从舒亳 JWT
44.
亠仆亳亳从舒亳 JWT
$ curl -H 'Authorization: Token token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9. eyJ1c2VyX2lkIjoxfQ.y8f9uijQS6sxeX58dQH4fwJYLxvmBt3HHAvnrj5w1Rg"' http://api. pumpkins.ua:3000/v1/pumpkins
45.
弌从舒 JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.
eyJ1c2VyX2lkIjoxfQ. y8f9uijQS6sxeX58dQH4fwJYLxvmBt3HHAvnrj5w1Rg 舒亞仂仍仂于仂从 (亳仗 仂仂弍亠仆亳 亳 舒仍亞仂亳仄, JSON + Base64) 丐亠仍仂 仂仂弍亠仆亳 (JSON + Base64) 仂亟仗亳 (亠仍仂 + 亰舒亞仂仍仂于仂从, 亰舒亳仂于舒仆仆亠 亠从亠仆仄 从仍ム仂仄)
46.
仂仗仂弍亠仄 仗仂亟仄亠仆亳 亟舒仆仆亠
亠仍仂 仂仂弍亠仆亳
47.
丐亠仄 仆亠 仄亠仆亠亠,
仂从亠仆 于亠 亠亠 仄仂亢仆仂 仗亠亠于舒亳!
48.
Expiration
49.
github.com/rgorel/pumpkins
50.
舒亳 于仂仗仂
Download