Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Restful on web service
Search
SparrowJang
March 20, 2013
Programming
1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Restful on web service
This example uses backbone.js and express.js.
SparrowJang
March 20, 2013
Other Decks in Programming
See All in Programming
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
380
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
160
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
500
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
440
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
210
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
350
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
19k
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
110
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1.2k
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.7k
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
730
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
540
Docker and Python
trallard
47
4.1k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
YesSQL, Process and Tooling at Scale
rocio
174
15k
The Cult of Friendly URLs
andyhume
79
7k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Thoughts on Productivity
jonyablonski
76
5.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
790
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
Transcript
Restful on web service Sparrow Jang
None
HTTP Method method Data operate description GET read Get a
resource. POST create Create a resource without id. PUT update Update a resource or create a resource with id if not existed. DELETE delete Delete a resource
Restful URI action method uri show GET http://example/users/{id} list GET
http://example/users create POST http://example/users update PUT http://example/users/{id} delete DELETE http://example/users/{id}
Implement example • The backend uses node.js with express.js. •
backbone.js.
Express implements restful action code list app.get('/users', function( req, res
){ doSomething(); }); show app.get('/users/:id', function( req, res ){ doSomething(); }); create app.post('/users/:id', function( req, res ){ doSomething(); }); update app.put('/users/:id', function( req, res ){ doSomething(); }); delete app.delete('/users/:id', function( req, res ){ doSomething(); });
Show example app.get('/users/:id', function( req, res ){ var id =
req.params.id, result; if( id ) result = api.fetch( id ); res.send( result ); });
List example app.get('/users',function( req, res ){ var result = api.fetch();
res.send( result ); });
Backbone.js implements restful action code list collection.fetch(); show model.fetch(); create
collection.create({name:"Peter"},{wait: true}); model.save({name:"Peter"},{wait: true}); update model.save({name:"Peter"}); delete model.destroy();
Model example var User = Backbone.Model.extend({ //set path urlRoot :
'/users', //validate attrs by set or save validate:function( attrs, options ){ if( !attrs.name ) return "name is null."; }, ...
Response data from server Get /users/1 { "result": { "success":
true }, "user": { "id": 1, "name": "Tom" } }
... parse:function( response, options ){ //from server if( response.result &&
response.result.success ) return response.user; //from collection else if( !response.result ) return response } });
Response data from server Get /users { "result": { "success":
true }, "users": [ {"id": 1,"name": "Tom"}, {"id": 2,"name": "John"}, ...] }
Collection example var Users = Backbone.Collection.extend({ url: '/users', model:User, parse:function(
response, options ){ if( response.result.success ) return response.users; } });
The End 1. github 2. http://sparrowhome.twbbs.org/wordpress/