SlideShare une entreprise Scribd logo
1  sur  64
Rapid API Development with Sails
10/11/2017, 1:15-1:35pm
Justin James
DevOps Evangelist and Microsoft MVP
@digitaldrummerj
© AngularMIX All rights reserved.
https://www.angularmix.com
Deliver Value to Users
as Quickly as Possible!
© AngularMIX All rights reserved.
https://www.angularmix.com
Not Paid to Write
Infrastructure Code!
© AngularMIX All rights reserved.
https://www.angularmix.com
Create JavaScript Services
© AngularMIX All rights reserved.
https://www.angularmix.com
Auto-generated REST APIs
© AngularMIX All rights reserved.
https://www.angularmix.com
Any Database
© AngularMIX All rights reserved.
https://www.angularmix.com
Flexible and Configurable
© AngularMIX All rights reserved.
https://www.angularmix.com
Security Policies
© AngularMIX All rights reserved.
https://www.angularmix.com
Built-On Top of
© AngularMIX All rights reserved.
https://www.angularmix.com
Ridiculously Fast
© AngularMIX All rights reserved.
https://www.angularmix.com
Just Works
© AngularMIX All rights reserved.
https://www.angularmix.com
Does NOT hide the magic
© AngularMIX All rights reserved.
https://www.angularmix.com
© AngularMIX All rights reserved.
https://www.angularmix.com
Ultimately,
writing tiny amounts of code
gets you a ton!
© AngularMIX All rights reserved.
https://www.angularmix.com
Getting Started
© AngularMIX All rights reserved.
https://www.angularmix.com
Install
© AngularMIX All rights reserved.
https://www.angularmix.com
Install Sails
npm install –g sails
© AngularMIX All rights reserved.
https://www.angularmix.com
Create Project
sails new [Project Name] --no-linker --no-frontend
© AngularMIX All rights reserved.
https://www.angularmix.com
Generate API
sails generate api [Api Name]
© AngularMIX All rights reserved.
https://www.angularmix.com
Start Sails Dev Server
sails lift
© AngularMIX All rights reserved.
https://www.angularmix.com
Start Sails in Production
node app.js
© AngularMIX All rights reserved.
https://www.angularmix.com
Debug Sails Way #1
node --inspect app.js
© AngularMIX All rights reserved.
https://www.angularmix.com
Debug Sails Way #2
Use Visual Studio Code Built-In Debugger
© AngularMIX All rights reserved.
https://www.angularmix.com
function timeForSomeCode () {
……
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Controller - apicontrollers<Api Name>Controller.js
module.exports = {
};
© AngularMIX All rights reserved.
https://www.angularmix.com
Model - apimodels<Api Name>.js
module.exports = {
attributes: {
}
};
© AngularMIX All rights reserved.
https://www.angularmix.com
Using Api
 POST http://localhost:1337/<Api Name>
 GET http://localhost:1337/<Api Name>
 PUT http://localhost:1337/<Api Name>/:id
 DELETE http://localhost:1337/<Api Name>/:id
© AngularMIX All rights reserved.
https://www.angularmix.com
POST – http://localhost:1337/user
{
"email": "foo2@foo.com",
"lastName": "James",
"firstName": "Justin",
}
© AngularMIX All rights reserved.
https://www.angularmix.com
POST Response - http://localhost:1337/user
{
"email": "foo2@foo.com",
"lastName": "James",
"firstName": "Justin",
"createdAt": "2017-10-11T20:15:24.151Z",
"updatedAt": "2017-10-11T20:15:24.151Z",
"id": 1
}
© AngularMIX All rights reserved.
https://www.angularmix.com
GET Response – http://localhost:1337/user
[{
"email": "foo2@foo.com",
"lastName": "James",
"firstName": "Justin",
"createdAt": "2017-10-11T20:15:24.151Z",
"updatedAt": "2017-10-11T20:15:24.151Z",
"id": 1
}]
© AngularMIX All rights reserved.
https://www.angularmix.com
Build Out Model – apimodelsUser.js
module.exports = {
attributes: {
email: { required: true, unique: true, type: 'string' },
lastName: { required: true, type: 'string' },
firstName: { required: true, type: 'string' },
todoItems: {
collection: 'todo',
via: 'user',
},
},
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Build Out Model – apimodelsUser.js
module.exports = {
attributes: {
email: {required: true, unique: true, type: 'string' },
lastName: { required: true, type: 'string' },
firstName: { required: true, type: 'string' },
todoItems: {
collection: 'todo',
via: 'user',
},
},
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Build Out Model – apimodelsUser.js
module.exports = {
attributes: {
email: {required: true, unique: true, type: 'string' },
lastName: { required: true, type: 'string' },
firstName: { required: true, type: 'string' },
todoItems: {
collection: 'todo',
via: 'user',
},
},
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Build Out Model – apimodelsUser.js
module.exports = {
attributes: {
email: {required: true, unique: true, type: 'string' },
lastName: { required: true, type: 'string' },
firstName: { required: true, type: 'string' },
todoItems: {
collection: 'todo',
via: 'user',
},
},
}
© AngularMIX All rights reserved.
https://www.angularmix.com
One to Many – apimodelsTodo.js
module.exports = {
attributes: {
.....
user: {
model: 'User',
}
}
};
© AngularMIX All rights reserved.
https://www.angularmix.com
Override Built-In REST verbs
module.exports = {
find: function findFn(req, res) {}, // GET
findOne: function findOneFn(req, res) {}, // GET/id
create: function createFn(req, res) {}, // POST
update: function updateFn(req, res) {}, // PUT
delete: function deleteFn(req, res) {}, // DELETE
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User – http://localhost:1337/user/:id
findOne: function findOneFn(req, res) {
User.findOne({ id: req.param('id') })
.populate('todoItems')
.exec(function (err, user) {
if (err) return res.serverError(err);
if (!user) return res.notFound();
return res.ok(user);
});
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User – http://localhost:1337/user/:id
findOne: function findOneFn(req, res) {
User.findOne({ id: req.param('id') })
.populate('todoItems')
.exec(function (err, user) {
if (err) return res.serverError(err);
if (!user) return res.notFound();
return res.ok(user);
});
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User – http://localhost:1337/user/:id
findOne: function findOneFn(req, res) {
User.findOne({ id: req.param('id') })
.populate('todoItems')
.exec(function (err, user) {
if (err) return res.serverError(err);
if (!user) return res.notFound();
return res.ok(user);
});
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User – http://localhost:1337/user/:id
findOne: function findOneFn(req, res) {
User.findOne({ id: req.param('id') })
.populate('todoItems')
.exec(function (err, user) {
if (err) return res.serverError(err);
if (!user) return res.notFound();
return res.ok(user);
});
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User – http://localhost:1337/user/:id
findOne: function findOneFn(req, res) {
User.findOne({ id: req.param('id') })
.populate('todoItems')
.exec(function (err, user) {
if (err) return res.serverError(err);
if (!user) return res.notFound();
return res.ok(user);
});
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User – http://localhost:1337/user/:id
findOne: function findOneFn(req, res) {
User.findOne({ id: req.param('id') })
.populate('todoItems')
.exec(function (err, user) {
if (err) return res.serverError(err);
if (!user) return res.notFound();
return res.ok(user);
});
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User – http://localhost:1337/user/:id
findOne: function findOneFn(req, res) {
User.findOne({ id: req.param('id') })
.populate('todoItems')
.exec(function (err, user) {
if (err) return res.serverError(err);
if (!user) return res.notFound();
return res.ok(user);
});
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User – http://localhost:1337/user/:id
findOne: function findOneFn(req, res) {
User.findOne({ id: req.param('id') })
.populate('todoItems')
.exec(function (err, user) {
if (err) return res.serverError(err);
if (!user) return res.notFound();
return res.ok(user);
});
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Get User Response – http://localhost:1337/user/:id
{
"todoItems": [],
"email": "foo2@foo.com",
"lastName": "James",
"firstName": "Justin",
"createdAt": "2017-10-10T15:39:06.838Z",
"updatedAt": "2017-10-10T15:39:06.838Z",
"id": 1
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Security – apipoliciesisLoggedIn.js
module.exports = function(req, res, next) {
if (req.session.user) return next();
return res.forbidden('Please Login First.');
};
© AngularMIX All rights reserved.
https://www.angularmix.com
Security – apipoliciesisLoggedIn.js
module.exports = function(req, res, next) {
if (req.session.user) return next();
return res.forbidden('Please Login First.');
};
© AngularMIX All rights reserved.
https://www.angularmix.com
Security – apipoliciesisLoggedIn.js
module.exports = function(req, res, next) {
if (req.session.user) return next();
return res.forbidden('Please Login First.');
};
© AngularMIX All rights reserved.
https://www.angularmix.com
Security – apipoliciesisLoggedIn.js
module.exports = function(req, res, next) {
if (req.session.user) return next();
return res.forbidden('Please Login First.');
};
© AngularMIX All rights reserved.
https://www.angularmix.com
Implement Policy– configpolicies.js
module.exports.policies = {
UserController: {
create: ['isLoggedOut'],
login: ['isLoggedOut'],
'*': ['isLoggedIn'],
},
TodoController: {
'*': ['isLoggedIn']
}
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Implement Policy– configpolicies.js
module.exports.policies = {
UserController: {
create: ['isLoggedOut'],
login: ['isLoggedOut'],
'*': ['isLoggedIn'],
},
TodoController: {
'*': ['isLoggedIn']
}
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Implement Policy– configpolicies.js
module.exports.policies = {
UserController: {
create: ['isLoggedOut'],
login: ['isLoggedOut'],
'*': ['isLoggedIn'],
},
TodoController: {
'*': ['isLoggedIn']
}
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Implement Policy– configpolicies.js
module.exports.policies = {
UserController: {
create: ['isLoggedOut'],
login: ['isLoggedOut'],
'*': ['isLoggedIn'],
},
TodoController: {
'*': ['isLoggedIn']
}
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Implement Policy– configpolicies.js
module.exports.policies = {
UserController: {
create: ['isLoggedOut'],
login: ['isLoggedOut'],
'*': ['isLoggedIn'],
},
TodoController: {
'*': ['isLoggedIn']
}
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Implement Policy– configpolicies.js
module.exports.policies = {
UserController: {
create: ['isLoggedOut'],
login: ['isLoggedOut'],
'*': ['isLoggedIn'],
},
TodoController: {
'*': ['isLoggedIn']
}
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Implement Policy– configpolicies.js
module.exports.policies = {
UserController: {
create: ['isLoggedOut'],
login: ['isLoggedOut'],
'*': ['isLoggedIn'],
},
TodoController: {
'*': ['isLoggedIn']
}
}
© AngularMIX All rights reserved.
https://www.angularmix.com
Custom Function – apiControllersUserController.js
userIdentity: function (req, res) {
....
},
© AngularMIX All rights reserved.
https://www.angularmix.com
Custom Function – apiControllersUserController.js
userIdentity: function (req, res) {
....
},
URL: http://localhost:1337/user/userIdentity
© AngularMIX All rights reserved.
https://www.angularmix.com
Routes – config/routes.js
module.exports.routes = {
'GET /user/identity': 'UserController.userIdentity',
};
© AngularMIX All rights reserved.
https://www.angularmix.com
References
 Documentation:
 http://sailsjs.com/
 Slides:
 https://slideshare.net/digitaldrummerj
 Demo Code:
 https://github.com/digitaldrummerj/angular-mix
 Tutorial:
 http://digitaldrummerj.me/sails-tutorial
© AngularMIX All rights reserved.
https://www.angularmix.com
digitaldrummerj.me
digitaldrummerj
© AngularMIX All rights reserved.
https://www.angularmix.com
Please use EventsXD to fill out a session evaluation.
Thank you!
© AngularMIX All rights reserved.
https://www.angularmix.com
Please use EventsXD to fill out a session evaluation.
Thank you!
© AngularMIX All rights reserved.
https://www.angularmix.com
Sails
Solves These

Contenu connexe

Dernier

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 

Dernier (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Rapid Api Development With Sails at Angular Mix

  • 1. Rapid API Development with Sails 10/11/2017, 1:15-1:35pm Justin James DevOps Evangelist and Microsoft MVP @digitaldrummerj
  • 2. © AngularMIX All rights reserved. https://www.angularmix.com Deliver Value to Users as Quickly as Possible!
  • 3. © AngularMIX All rights reserved. https://www.angularmix.com Not Paid to Write Infrastructure Code!
  • 4. © AngularMIX All rights reserved. https://www.angularmix.com Create JavaScript Services
  • 5. © AngularMIX All rights reserved. https://www.angularmix.com Auto-generated REST APIs
  • 6. © AngularMIX All rights reserved. https://www.angularmix.com Any Database
  • 7. © AngularMIX All rights reserved. https://www.angularmix.com Flexible and Configurable
  • 8. © AngularMIX All rights reserved. https://www.angularmix.com Security Policies
  • 9. © AngularMIX All rights reserved. https://www.angularmix.com Built-On Top of
  • 10. © AngularMIX All rights reserved. https://www.angularmix.com Ridiculously Fast
  • 11. © AngularMIX All rights reserved. https://www.angularmix.com Just Works
  • 12. © AngularMIX All rights reserved. https://www.angularmix.com Does NOT hide the magic
  • 13. © AngularMIX All rights reserved. https://www.angularmix.com
  • 14. © AngularMIX All rights reserved. https://www.angularmix.com Ultimately, writing tiny amounts of code gets you a ton!
  • 15. © AngularMIX All rights reserved. https://www.angularmix.com Getting Started
  • 16. © AngularMIX All rights reserved. https://www.angularmix.com Install
  • 17. © AngularMIX All rights reserved. https://www.angularmix.com Install Sails npm install –g sails
  • 18. © AngularMIX All rights reserved. https://www.angularmix.com Create Project sails new [Project Name] --no-linker --no-frontend
  • 19. © AngularMIX All rights reserved. https://www.angularmix.com Generate API sails generate api [Api Name]
  • 20. © AngularMIX All rights reserved. https://www.angularmix.com Start Sails Dev Server sails lift
  • 21. © AngularMIX All rights reserved. https://www.angularmix.com Start Sails in Production node app.js
  • 22. © AngularMIX All rights reserved. https://www.angularmix.com Debug Sails Way #1 node --inspect app.js
  • 23. © AngularMIX All rights reserved. https://www.angularmix.com Debug Sails Way #2 Use Visual Studio Code Built-In Debugger
  • 24. © AngularMIX All rights reserved. https://www.angularmix.com function timeForSomeCode () { …… }
  • 25. © AngularMIX All rights reserved. https://www.angularmix.com Controller - apicontrollers<Api Name>Controller.js module.exports = { };
  • 26. © AngularMIX All rights reserved. https://www.angularmix.com Model - apimodels<Api Name>.js module.exports = { attributes: { } };
  • 27. © AngularMIX All rights reserved. https://www.angularmix.com Using Api  POST http://localhost:1337/<Api Name>  GET http://localhost:1337/<Api Name>  PUT http://localhost:1337/<Api Name>/:id  DELETE http://localhost:1337/<Api Name>/:id
  • 28. © AngularMIX All rights reserved. https://www.angularmix.com POST – http://localhost:1337/user { "email": "foo2@foo.com", "lastName": "James", "firstName": "Justin", }
  • 29. © AngularMIX All rights reserved. https://www.angularmix.com POST Response - http://localhost:1337/user { "email": "foo2@foo.com", "lastName": "James", "firstName": "Justin", "createdAt": "2017-10-11T20:15:24.151Z", "updatedAt": "2017-10-11T20:15:24.151Z", "id": 1 }
  • 30. © AngularMIX All rights reserved. https://www.angularmix.com GET Response – http://localhost:1337/user [{ "email": "foo2@foo.com", "lastName": "James", "firstName": "Justin", "createdAt": "2017-10-11T20:15:24.151Z", "updatedAt": "2017-10-11T20:15:24.151Z", "id": 1 }]
  • 31. © AngularMIX All rights reserved. https://www.angularmix.com Build Out Model – apimodelsUser.js module.exports = { attributes: { email: { required: true, unique: true, type: 'string' }, lastName: { required: true, type: 'string' }, firstName: { required: true, type: 'string' }, todoItems: { collection: 'todo', via: 'user', }, }, }
  • 32. © AngularMIX All rights reserved. https://www.angularmix.com Build Out Model – apimodelsUser.js module.exports = { attributes: { email: {required: true, unique: true, type: 'string' }, lastName: { required: true, type: 'string' }, firstName: { required: true, type: 'string' }, todoItems: { collection: 'todo', via: 'user', }, }, }
  • 33. © AngularMIX All rights reserved. https://www.angularmix.com Build Out Model – apimodelsUser.js module.exports = { attributes: { email: {required: true, unique: true, type: 'string' }, lastName: { required: true, type: 'string' }, firstName: { required: true, type: 'string' }, todoItems: { collection: 'todo', via: 'user', }, }, }
  • 34. © AngularMIX All rights reserved. https://www.angularmix.com Build Out Model – apimodelsUser.js module.exports = { attributes: { email: {required: true, unique: true, type: 'string' }, lastName: { required: true, type: 'string' }, firstName: { required: true, type: 'string' }, todoItems: { collection: 'todo', via: 'user', }, }, }
  • 35. © AngularMIX All rights reserved. https://www.angularmix.com One to Many – apimodelsTodo.js module.exports = { attributes: { ..... user: { model: 'User', } } };
  • 36. © AngularMIX All rights reserved. https://www.angularmix.com Override Built-In REST verbs module.exports = { find: function findFn(req, res) {}, // GET findOne: function findOneFn(req, res) {}, // GET/id create: function createFn(req, res) {}, // POST update: function updateFn(req, res) {}, // PUT delete: function deleteFn(req, res) {}, // DELETE }
  • 37. © AngularMIX All rights reserved. https://www.angularmix.com Get User – http://localhost:1337/user/:id findOne: function findOneFn(req, res) { User.findOne({ id: req.param('id') }) .populate('todoItems') .exec(function (err, user) { if (err) return res.serverError(err); if (!user) return res.notFound(); return res.ok(user); }); },
  • 38. © AngularMIX All rights reserved. https://www.angularmix.com Get User – http://localhost:1337/user/:id findOne: function findOneFn(req, res) { User.findOne({ id: req.param('id') }) .populate('todoItems') .exec(function (err, user) { if (err) return res.serverError(err); if (!user) return res.notFound(); return res.ok(user); }); },
  • 39. © AngularMIX All rights reserved. https://www.angularmix.com Get User – http://localhost:1337/user/:id findOne: function findOneFn(req, res) { User.findOne({ id: req.param('id') }) .populate('todoItems') .exec(function (err, user) { if (err) return res.serverError(err); if (!user) return res.notFound(); return res.ok(user); }); },
  • 40. © AngularMIX All rights reserved. https://www.angularmix.com Get User – http://localhost:1337/user/:id findOne: function findOneFn(req, res) { User.findOne({ id: req.param('id') }) .populate('todoItems') .exec(function (err, user) { if (err) return res.serverError(err); if (!user) return res.notFound(); return res.ok(user); }); },
  • 41. © AngularMIX All rights reserved. https://www.angularmix.com Get User – http://localhost:1337/user/:id findOne: function findOneFn(req, res) { User.findOne({ id: req.param('id') }) .populate('todoItems') .exec(function (err, user) { if (err) return res.serverError(err); if (!user) return res.notFound(); return res.ok(user); }); },
  • 42. © AngularMIX All rights reserved. https://www.angularmix.com Get User – http://localhost:1337/user/:id findOne: function findOneFn(req, res) { User.findOne({ id: req.param('id') }) .populate('todoItems') .exec(function (err, user) { if (err) return res.serverError(err); if (!user) return res.notFound(); return res.ok(user); }); },
  • 43. © AngularMIX All rights reserved. https://www.angularmix.com Get User – http://localhost:1337/user/:id findOne: function findOneFn(req, res) { User.findOne({ id: req.param('id') }) .populate('todoItems') .exec(function (err, user) { if (err) return res.serverError(err); if (!user) return res.notFound(); return res.ok(user); }); },
  • 44. © AngularMIX All rights reserved. https://www.angularmix.com Get User – http://localhost:1337/user/:id findOne: function findOneFn(req, res) { User.findOne({ id: req.param('id') }) .populate('todoItems') .exec(function (err, user) { if (err) return res.serverError(err); if (!user) return res.notFound(); return res.ok(user); }); },
  • 45. © AngularMIX All rights reserved. https://www.angularmix.com Get User Response – http://localhost:1337/user/:id { "todoItems": [], "email": "foo2@foo.com", "lastName": "James", "firstName": "Justin", "createdAt": "2017-10-10T15:39:06.838Z", "updatedAt": "2017-10-10T15:39:06.838Z", "id": 1 }
  • 46. © AngularMIX All rights reserved. https://www.angularmix.com Security – apipoliciesisLoggedIn.js module.exports = function(req, res, next) { if (req.session.user) return next(); return res.forbidden('Please Login First.'); };
  • 47. © AngularMIX All rights reserved. https://www.angularmix.com Security – apipoliciesisLoggedIn.js module.exports = function(req, res, next) { if (req.session.user) return next(); return res.forbidden('Please Login First.'); };
  • 48. © AngularMIX All rights reserved. https://www.angularmix.com Security – apipoliciesisLoggedIn.js module.exports = function(req, res, next) { if (req.session.user) return next(); return res.forbidden('Please Login First.'); };
  • 49. © AngularMIX All rights reserved. https://www.angularmix.com Security – apipoliciesisLoggedIn.js module.exports = function(req, res, next) { if (req.session.user) return next(); return res.forbidden('Please Login First.'); };
  • 50. © AngularMIX All rights reserved. https://www.angularmix.com Implement Policy– configpolicies.js module.exports.policies = { UserController: { create: ['isLoggedOut'], login: ['isLoggedOut'], '*': ['isLoggedIn'], }, TodoController: { '*': ['isLoggedIn'] } }
  • 51. © AngularMIX All rights reserved. https://www.angularmix.com Implement Policy– configpolicies.js module.exports.policies = { UserController: { create: ['isLoggedOut'], login: ['isLoggedOut'], '*': ['isLoggedIn'], }, TodoController: { '*': ['isLoggedIn'] } }
  • 52. © AngularMIX All rights reserved. https://www.angularmix.com Implement Policy– configpolicies.js module.exports.policies = { UserController: { create: ['isLoggedOut'], login: ['isLoggedOut'], '*': ['isLoggedIn'], }, TodoController: { '*': ['isLoggedIn'] } }
  • 53. © AngularMIX All rights reserved. https://www.angularmix.com Implement Policy– configpolicies.js module.exports.policies = { UserController: { create: ['isLoggedOut'], login: ['isLoggedOut'], '*': ['isLoggedIn'], }, TodoController: { '*': ['isLoggedIn'] } }
  • 54. © AngularMIX All rights reserved. https://www.angularmix.com Implement Policy– configpolicies.js module.exports.policies = { UserController: { create: ['isLoggedOut'], login: ['isLoggedOut'], '*': ['isLoggedIn'], }, TodoController: { '*': ['isLoggedIn'] } }
  • 55. © AngularMIX All rights reserved. https://www.angularmix.com Implement Policy– configpolicies.js module.exports.policies = { UserController: { create: ['isLoggedOut'], login: ['isLoggedOut'], '*': ['isLoggedIn'], }, TodoController: { '*': ['isLoggedIn'] } }
  • 56. © AngularMIX All rights reserved. https://www.angularmix.com Implement Policy– configpolicies.js module.exports.policies = { UserController: { create: ['isLoggedOut'], login: ['isLoggedOut'], '*': ['isLoggedIn'], }, TodoController: { '*': ['isLoggedIn'] } }
  • 57. © AngularMIX All rights reserved. https://www.angularmix.com Custom Function – apiControllersUserController.js userIdentity: function (req, res) { .... },
  • 58. © AngularMIX All rights reserved. https://www.angularmix.com Custom Function – apiControllersUserController.js userIdentity: function (req, res) { .... }, URL: http://localhost:1337/user/userIdentity
  • 59. © AngularMIX All rights reserved. https://www.angularmix.com Routes – config/routes.js module.exports.routes = { 'GET /user/identity': 'UserController.userIdentity', };
  • 60. © AngularMIX All rights reserved. https://www.angularmix.com References  Documentation:  http://sailsjs.com/  Slides:  https://slideshare.net/digitaldrummerj  Demo Code:  https://github.com/digitaldrummerj/angular-mix  Tutorial:  http://digitaldrummerj.me/sails-tutorial
  • 61. © AngularMIX All rights reserved. https://www.angularmix.com digitaldrummerj.me digitaldrummerj
  • 62. © AngularMIX All rights reserved. https://www.angularmix.com Please use EventsXD to fill out a session evaluation. Thank you!
  • 63. © AngularMIX All rights reserved. https://www.angularmix.com Please use EventsXD to fill out a session evaluation. Thank you!
  • 64. © AngularMIX All rights reserved. https://www.angularmix.com Sails Solves These

Notes de l'éditeur

  1. https://nodejs.org/static/images/logos/nodejs-new-pantone-black.png
  2. http://www.robinsonfirm.com/wp-content/themes/attorney/photos/roadway-design-lawyer.jpg Rules to say how to handle incoming request Work with HTTP and WebSockets Two types:  automatic (or "implicit") custom (or "explicit")
  3. http://zdnet3.cbsistatic.com/hub/i/2014/11/28/dd55490d-76b3-11e4-b569-d4ae52e95e57/3451ad4c361a98b89fe2fe9f9fdec94f/amazon-vs-oracle-a-database-war.png Uses Waterline ORM Uses models to represent tables and relationships Can mix and match models between data stores Pre-configured to use JSON file store
  4. https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAZ5AAAAJDcyNjRhOWEzLTYzMDktNGJiZC05YTcwLTg5MzkyNjJiNTdkZg.jpg
  5. https://i.kinja-img.com/gawker-media/image/upload/s--uFoN6YYf--/c_scale,fl_progressive,q_80,w_800/jgpeuoavmn7pwbh98ycs.jpg Implemented using policies Can use any scheme Apply to individual action or entire controller Designed to be chained together
  6. http://mean.io/wp-content/themes/twentysixteen-child/images/express.png
  7. http://inlight.com.au/img/blog-main/main-how-to-make-your-website-load-ridiculously-fast.jpg http://1.bp.blogspot.com/-V6bdiIwfZxs/VXH1VbwOh8I/AAAAAAAAAw8/61Jt-OuuT98/s1600/Speedy.png
  8. https://pbs.twimg.com/profile_images/53902894/jwnhlogo02_logoonly.png
  9. http://goodheads.io/wp-content/uploads/2016/02/magic_method_bulb.jpg
  10. https://appeltechsolutions.com/wp-content/uploads/2013/06/free.jpg
  11. https://nodejs.org/static/images/logos/nodejs-new-pantone-black.png
  12. Done