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
1
1k
Restful on web service
This example uses backbone.js and express.js.
SparrowJang
March 20, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
マンガアプリViewerの大画面対応を考える
kk__777
0
450
CSC509 Lecture 10
javiergs
PRO
0
160
Blazing Fast UI Development with Compose Hot Reload (Bangladesh KUG, October 2025)
zsmb
2
450
開発組織の戦略的な役割と 設計スキル向上の効果
masuda220
PRO
10
2k
AI Agent 時代的開發者生存指南
eddie
4
2.3k
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
250
CSC305 Lecture 13
javiergs
PRO
0
350
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
1.1k
Amazon ECS Managed Instances が リリースされた!キャッチアップしよう!! / Let's catch up Amazon ECS Managed Instances
cocoeyes02
0
120
ノーコードからの脱出 -地獄のデスロード- / Escape from Base44
keisuke69
0
350
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
200
Introduce Hono CLI
yusukebe
6
3.3k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
36
7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
Become a Pro
speakerdeck
PRO
29
5.6k
Documentation Writing (for coders)
carmenintech
76
5.1k
Mobile First: as difficult as doing things right
swwweet
225
10k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
How STYLIGHT went responsive
nonsquared
100
5.9k
The Invisible Side of Design
smashingmag
302
51k
Rails Girls Zürich Keynote
gr2m
95
14k
We Have a Design System, Now What?
morganepeng
54
7.9k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
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/