Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
APNsからLive Activityを開始する話
yumnumm
0
170
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
220
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
520
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Being A Developer After 40
akosma
92
590k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
280
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
270
A Tale of Four Properties
chriscoyier
163
24k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
540
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
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/