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
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
220
ローカルLLMを⽤いてコード補完を⾏う VSCode拡張機能を作ってみた
nearme_tech
PRO
0
180
複雑なUI設計への銀の弾丸 「オブジェクト指向UIデザイン」
teamlab
PRO
2
110
Developing static sites with Ruby
okuramasafumi
0
330
Graviton と Nitro と私
maroon1st
0
140
PostgreSQLで手軽にDuckDBを使う!DuckDB&pg_duckdb入門/osc25hi-duckdb
takahashiikki
0
180
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
200
ELYZA_Findy AI Engineering Summit登壇資料_AIコーディング時代に「ちゃんと」やること_toB LLMプロダクト開発舞台裏_20251216
elyza
2
650
Java 25, Nuevas características
czelabueno
0
120
Deno Tunnel を使ってみた話
kamekyame
0
260
Context is King? 〜Verifiability時代とコンテキスト設計 / Beyond "Context is King"
rkaga
10
1.4k
Cell-Based Architecture
larchanjo
0
140
Featured
See All Featured
The Limits of Empathy - UXLibs8
cassininazir
1
190
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Site-Speed That Sticks
csswizardry
13
1k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.3k
It's Worth the Effort
3n
187
29k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
94
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
120
Accessibility Awareness
sabderemane
0
24
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
0
46
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Tell your own story through comics
letsgokoyo
0
770
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/