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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
SparrowJang
March 20, 2013
Programming
1k
1
Share
Restful on web service
This example uses backbone.js and express.js.
SparrowJang
March 20, 2013
Other Decks in Programming
See All in Programming
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
230
KagglerがMixSeekを触ってみた
morim
0
350
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
270
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
280
RailsのValidatesをSwift Macrosで再現してみた
hokuron
0
140
Symfonyの特性(設計思想)を手軽に活かす特性(trait)
ickx
0
110
へんな働き方
yusukebe
6
2.9k
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
1
190
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
130
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
Strategy for Finding a Problem for OSS: With Real Examples
kibitan
0
130
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
290
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
610
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
240
From π to Pie charts
rasagy
0
160
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
320
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
43k
Crafting Experiences
bethany
1
100
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Writing Fast Ruby
sferik
630
63k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
SEO for Brand Visibility & Recognition
aleyda
0
4.4k
Prompt Engineering for Job Search
mfonobong
0
240
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/