SlideShare une entreprise Scribd logo
1  sur  59
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à Api.js

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 6
asmediagroup1
 
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
Apigee | Google Cloud
 

Similaire à 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
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Api.js