SlideShare una empresa de Scribd logo
1 de 59
Descargar para leer sin conexión
A
P
I
Patrick
Heneise
Apis,Egyptiangodofstrengthandfertility
http://icity-devp.icityproject.com
Let’stalkabout
yourAPI
WhatmakesagoodAPI?
★ Performance
★ Scalability
★ Reusability
★ Evolvability
★ Documentation
★ Testability
★ Value
★ Easytolearn&use
★ Hardtomisuse
‘OnceyouhaveabadAPI,youcannotchange
it.Forever.You’vegotonechancehowto
makeitright.’–JoshuaBloch,GoogleTechTalk,Jan2007
Whynode.jsisthe
righttool!
★ Double-clicktoedit.
It’snot.
Chooseyour
weaponscarefully!
Butnode.jshassome
nicefeatures.
Andit’scool.
Becauseit’sJavaScript.
AndJavaScriptiscool,
right?
Solet’screatean
APIinnode.js
TheDemoAPI
TheCatAPI!
Seriously?
So,introducing:
TheJunkAPI
https://github.com/
PatrickHeneise/TheJunkAPI
‘AnAPIshoulddoonething,andtoitwell.’
JoshuaBloch,GoogleTechTalk,Jan2007
Adding,listing,
showinganddeleting:
Junk.
app.get('/api/junks',junk.index);
app.get('/api/junk/:id',junk.show);
app.post('/api/junk',junk.create);
app.delete('/api/junk/:id',junk.remove);
exports.show=function(req,res){
varid=req.params.id;
redis.hgetall('junk:'+id,function(error,junk){
if(junk===null){
res.send(404);
}else{
res.send(200,junk);
}
});
};
Input/Output
★ params:/api/junk/1
★ query:/api/junk?id=1
★ body:/api/junk-d{‘id’:1}
★ Chooseyourweaponcarefully!
Input
★ HTTPStatusCodes
★ ResponseBody
★ Usethestandards!
Output
★ 200-Success
★ 201-Created
★ 204-Nocontent
★ 401-Unauthorized
★ 403-Forbidden
★ 404-NotFound
★ 409-Conflict
★ 500-InternalServer
Error
HTTPStatusCodes
res.send(200,{});
Authentication
passport.js
★ OAuth
★ OAuth2
★ apikey
★ HTTPBasic
★ HTTPDigest
★ ...
Again,chooseyour
weaponcarefully!
Testing
★ mocha
http://visionmedia.github.io/
mocha/
★ vows
http://vowsjs.org
★ specify
https://github.com/dscape/
specify
mocha
describe('GET /junk/:id', function () {
it('should return details of the junk', function (done) {
request(url)
.get('/junk/0')
.set('apikey', 'asdasjsdgfjkjhg')
.send()
.end(function (error, response) {
response.status.should.equal(200);
response.body.text.should.equal('iz likin myself on lolcats.com');
should.exist(response.body.url);
done(error);
});
});
Prepareyour
testing
environment!
‘Andcleanupafterwards!’-Mum
before(function(done){
! require('./before').before(function(){
! ! done();
! })
});
after(function(done){
! require('./after').after(ids,function(){
! ! done();
! });
});
Junk
GET /junks
✓ should return a list of junk
GET /junk/:id
✓ should return details of the junk
✓ should fail with 404
POST /junk
✓ should create new junk
✓ should fail to create new junk
DELETE /junk/:id
✓ should delete junk, huzzah!
✓ should fail to delete junk
7 passing (1s)
Yay.✓
Documentation
★ http://jsdox.org
★ https://github.com/visionmedia/
dox-JavaScriptdocumentation
generator
★ https://github.com/mashery/
iodocs-I/ODocs-OpenSourcein
Node.js
Dox
/**
*Outputasinglepieceofjunk
specifiedby:id
*
*@param{Number}id
*@return{Object}Alljunkdetails
*@apipublic
*/
iodocs
Resources
(nomorecats)
★ HowToDesignAGoodAPIandWhy
itMattershttp://www.youtube.com/watch?v=aAb7hSCtvGw http://lcsd05.cs.tamu.edu/
slides/keynote.pdf
★ http://stackoverflow.com/
questions/2619854/best-practices-
and-guidelines-for-designing-an-
api
★ https://dev.twitter.com//
Thankyou.
PatrickHeneise
@PatrickHeneise
http://patrickheneise.com

Más contenido relacionado

Similar a Api.js

From Napkin to Network: Rapidly Design, Prototype and Leverage Network APIs
From Napkin to Network: Rapidly Design, Prototype and Leverage Network APIsFrom Napkin to Network: Rapidly Design, Prototype and Leverage Network APIs
From Napkin to Network: Rapidly Design, Prototype and Leverage Network APIsApigee | Google Cloud
 
Is your API misbehaving?(Keith-Casey)
Is your API misbehaving?(Keith-Casey)Is your API misbehaving?(Keith-Casey)
Is your API misbehaving?(Keith-Casey)Future Insights
 
Prototype4Production Presented at FOSSASIA2015 at Singapore
Prototype4Production Presented at FOSSASIA2015 at SingaporePrototype4Production Presented at FOSSASIA2015 at Singapore
Prototype4Production Presented at FOSSASIA2015 at SingaporeDhruv Gohil
 
Development without Testers: Myth or Real Option?
Development without Testers: Myth or Real Option?Development without Testers: Myth or Real Option?
Development without Testers: Myth or Real Option?Mikalai Alimenkou
 
Dances with unicorns
Dances with unicornsDances with unicorns
Dances with unicornsEspritAgile
 
Can we fix dev-oops ?
Can we fix dev-oops ?Can we fix dev-oops ?
Can we fix dev-oops ?Kris Buytaert
 
Development without Testers: Myth or Real Option? (ConfeT&QA conference)
Development without Testers: Myth or Real Option? (ConfeT&QA conference)Development without Testers: Myth or Real Option? (ConfeT&QA conference)
Development without Testers: Myth or Real Option? (ConfeT&QA conference)Mikalai Alimenkou
 
Question 4 How did you use media technologies in the construction and researc...
Question 4 How did you use media technologies in the construction and researc...Question 4 How did you use media technologies in the construction and researc...
Question 4 How did you use media technologies in the construction and researc...Nay4697
 
Evaluation- Question 6
Evaluation- Question 6Evaluation- Question 6
Evaluation- Question 6asmediagroup1
 
From Napkin to App: Rapidly Prototype and Build for Mobile in Days
From Napkin to App:  Rapidly Prototype and Build for Mobile in DaysFrom Napkin to App:  Rapidly Prototype and Build for Mobile in Days
From Napkin to App: Rapidly Prototype and Build for Mobile in DaysApigee | Google Cloud
 
Appium tips & Inneractive integration
Appium tips & Inneractive integrationAppium tips & Inneractive integration
Appium tips & Inneractive integrationGil Sheps
 
Evaluation Question 6
Evaluation Question 6Evaluation Question 6
Evaluation Question 6asmediagroup1
 
Evaluation- Question 6
Evaluation- Question 6Evaluation- Question 6
Evaluation- Question 6asmediagroup1
 
A tour of React Native
A tour of React NativeA tour of React Native
A tour of React NativeTadeu Zagallo
 
The Developer Experience
The Developer Experience The Developer Experience
The Developer Experience Pamela Fox
 
Evaluation- Question 6
Evaluation- Question 6Evaluation- Question 6
Evaluation- Question 6asmediagroup1
 
[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differentlyTomomi Imura
 
The Developer Experience
The Developer ExperienceThe Developer Experience
The Developer ExperienceAtlassian
 

Similar a Api.js (20)

From Napkin to Network: Rapidly Design, Prototype and Leverage Network APIs
From Napkin to Network: Rapidly Design, Prototype and Leverage Network APIsFrom Napkin to Network: Rapidly Design, Prototype and Leverage Network APIs
From Napkin to Network: Rapidly Design, Prototype and Leverage Network APIs
 
Is your API misbehaving?(Keith-Casey)
Is your API misbehaving?(Keith-Casey)Is your API misbehaving?(Keith-Casey)
Is your API misbehaving?(Keith-Casey)
 
Prototype4Production Presented at FOSSASIA2015 at Singapore
Prototype4Production Presented at FOSSASIA2015 at SingaporePrototype4Production Presented at FOSSASIA2015 at Singapore
Prototype4Production Presented at FOSSASIA2015 at Singapore
 
Development without Testers: Myth or Real Option?
Development without Testers: Myth or Real Option?Development without Testers: Myth or Real Option?
Development without Testers: Myth or Real Option?
 
Dances with unicorns
Dances with unicornsDances with unicorns
Dances with unicorns
 
Can we fix dev-oops ?
Can we fix dev-oops ?Can we fix dev-oops ?
Can we fix dev-oops ?
 
Development without Testers: Myth or Real Option? (ConfeT&QA conference)
Development without Testers: Myth or Real Option? (ConfeT&QA conference)Development without Testers: Myth or Real Option? (ConfeT&QA conference)
Development without Testers: Myth or Real Option? (ConfeT&QA conference)
 
Presentation1
Presentation1Presentation1
Presentation1
 
Question 4 How did you use media technologies in the construction and researc...
Question 4 How did you use media technologies in the construction and researc...Question 4 How did you use media technologies in the construction and researc...
Question 4 How did you use media technologies in the construction and researc...
 
Evaluation- Question 6
Evaluation- Question 6Evaluation- Question 6
Evaluation- Question 6
 
From Napkin to App: Rapidly Prototype and Build for Mobile in Days
From Napkin to App:  Rapidly Prototype and Build for Mobile in DaysFrom Napkin to App:  Rapidly Prototype and Build for Mobile in Days
From Napkin to App: Rapidly Prototype and Build for Mobile in Days
 
Hacking101 delhi 2013
Hacking101 delhi 2013Hacking101 delhi 2013
Hacking101 delhi 2013
 
Appium tips & Inneractive integration
Appium tips & Inneractive integrationAppium tips & Inneractive integration
Appium tips & Inneractive integration
 
Evaluation Question 6
Evaluation Question 6Evaluation Question 6
Evaluation Question 6
 
Evaluation- Question 6
Evaluation- Question 6Evaluation- Question 6
Evaluation- Question 6
 
A tour of React Native
A tour of React NativeA tour of React Native
A tour of React Native
 
The Developer Experience
The Developer Experience The Developer Experience
The Developer Experience
 
Evaluation- Question 6
Evaluation- Question 6Evaluation- Question 6
Evaluation- Question 6
 
[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently
 
The Developer Experience
The Developer ExperienceThe Developer Experience
The Developer Experience
 

Último

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Api.js