SlideShare a Scribd company logo
1 of 35
Rack middlewares
The Ins & Outs
By: Ahmed Shahin
● What is Rack? Why?
● Sample Rack application
● What is Middleware?
● Enrich our Rack app with middlewares
● Use middlewares within a Rails app
● Watch-outs
Agenda
What is Rack?
What Is Rack?
What Is Rack?
What is Rack App?
● Any object that responds to a ‘call’ method
● Accepts ‘env’ parameter
● Returns a 3-elements array:
○ Status code #Integer
○ Headers # Hash
○ Body # Enumerable
Sample Rack App
Using middlewares
Let’s add some features!
● Redirection for obsolete pages
● Rate limiting
● Send every request url to a third party service.
What is Middleware?
Same as Rack App:
Also, constructor that takes ‘app’ argument
Middleware: Redirection for obsolete pages
Middleware: Rate limiting
Middleware: Call a third party service
Use them in the Rack app
Also, you can use them in a Rails app
And see them in action
Watch-outs
Performance
A solution: Use it when you actually need it
From “Warden” documentation
“Warden is designed to be lazy. That is, if you don't use it,
it doesn't do anything..”
Ordering
Single purpose
Conclusion
Middlewares are very powerful, Just be gentle with it!
Thank you!
https://github.com/codeminator
https://www.linkedin.com/in/codeminator

More Related Content

What's hot

The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
Sashko Stubailo
 

What's hot (20)

APIdays Paris 2019 - End-to-end Type-Safe GraphQL Apps by Carlos Rufo, GraphQ...
APIdays Paris 2019 - End-to-end Type-Safe GraphQL Apps by Carlos Rufo, GraphQ...APIdays Paris 2019 - End-to-end Type-Safe GraphQL Apps by Carlos Rufo, GraphQ...
APIdays Paris 2019 - End-to-end Type-Safe GraphQL Apps by Carlos Rufo, GraphQ...
 
Asp.net c# mvc Training Day-4 of Day-9
Asp.net c# mvc Training Day-4 of Day-9Asp.net c# mvc Training Day-4 of Day-9
Asp.net c# mvc Training Day-4 of Day-9
 
License plate detection using cloud api's
License plate detection using cloud api'sLicense plate detection using cloud api's
License plate detection using cloud api's
 
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/MeteorWhy UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
 
Hacking Real time Messaging with Firebase
Hacking Real time Messaging with FirebaseHacking Real time Messaging with Firebase
Hacking Real time Messaging with Firebase
 
No Graph Theory Required: Ember and GraphQL in Practice
No Graph Theory Required: Ember and GraphQL in PracticeNo Graph Theory Required: Ember and GraphQL in Practice
No Graph Theory Required: Ember and GraphQL in Practice
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
Modular GraphQL with Schema Stitching
Modular GraphQL with Schema StitchingModular GraphQL with Schema Stitching
Modular GraphQL with Schema Stitching
 
Into to GraphQL
Into to GraphQLInto to GraphQL
Into to GraphQL
 
Functional Reactive Endpoints using Spring 5
Functional Reactive Endpoints using Spring 5Functional Reactive Endpoints using Spring 5
Functional Reactive Endpoints using Spring 5
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
 
Monitoring with riemann
Monitoring with riemannMonitoring with riemann
Monitoring with riemann
 
Creando tu primera aplicación con Angular 2, el nuevo súper framework de Google
Creando tu primera aplicación con Angular 2, el nuevo súper framework de GoogleCreando tu primera aplicación con Angular 2, el nuevo súper framework de Google
Creando tu primera aplicación con Angular 2, el nuevo súper framework de Google
 
Extending the New Relic Platform
Extending the New Relic PlatformExtending the New Relic Platform
Extending the New Relic Platform
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
 
GraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend DevsGraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend Devs
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
Kafka and GraphQL: Misconceptions and Connections | Gerard Klijs, Open Web
Kafka and GraphQL: Misconceptions and Connections | Gerard Klijs, Open WebKafka and GraphQL: Misconceptions and Connections | Gerard Klijs, Open Web
Kafka and GraphQL: Misconceptions and Connections | Gerard Klijs, Open Web
 
Performance optimisation with GraphQL
Performance optimisation with GraphQLPerformance optimisation with GraphQL
Performance optimisation with GraphQL
 
HackTX
HackTXHackTX
HackTX
 

Similar to Rack middlewares - ins outs

App Engine overview (Android meetup 06-10)
App Engine overview (Android meetup 06-10)App Engine overview (Android meetup 06-10)
App Engine overview (Android meetup 06-10)
jasonacooper
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
Ruben Tan
 
Rails Request & Middlewares
Rails Request & MiddlewaresRails Request & Middlewares
Rails Request & Middlewares
Santosh Wadghule
 

Similar to Rack middlewares - ins outs (20)

Rails in the bowels
Rails in the bowelsRails in the bowels
Rails in the bowels
 
App Engine overview (Android meetup 06-10)
App Engine overview (Android meetup 06-10)App Engine overview (Android meetup 06-10)
App Engine overview (Android meetup 06-10)
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewares
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIs
 
High Performance Web Applications
High Performance Web ApplicationsHigh Performance Web Applications
High Performance Web Applications
 
DevOps Fest 2019. Gianluca Arbezzano. DevOps never sleeps. What we learned fr...
DevOps Fest 2019. Gianluca Arbezzano. DevOps never sleeps. What we learned fr...DevOps Fest 2019. Gianluca Arbezzano. DevOps never sleeps. What we learned fr...
DevOps Fest 2019. Gianluca Arbezzano. DevOps never sleeps. What we learned fr...
 
Forza Computazionale e Applicazioni Serverless
Forza Computazionale e Applicazioni ServerlessForza Computazionale e Applicazioni Serverless
Forza Computazionale e Applicazioni Serverless
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
Getting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless ComputingGetting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless Computing
 
Rapid mobile development using GraphQL and AWS AppSync
Rapid mobile development using GraphQL and AWS AppSyncRapid mobile development using GraphQL and AWS AppSync
Rapid mobile development using GraphQL and AWS AppSync
 
Rails Request & Middlewares
Rails Request & MiddlewaresRails Request & Middlewares
Rails Request & Middlewares
 
Streamlined Geek Talk
Streamlined Geek TalkStreamlined Geek Talk
Streamlined Geek Talk
 
Node.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniquesNode.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniques
 
2021 JCConf 使用Dapr簡化Java微服務應用開發
2021 JCConf 使用Dapr簡化Java微服務應用開發2021 JCConf 使用Dapr簡化Java微服務應用開發
2021 JCConf 使用Dapr簡化Java微服務應用開發
 
How to deploy your Apps in serverless-way using App Engine.pptx
How to deploy your Apps in serverless-way using App Engine.pptxHow to deploy your Apps in serverless-way using App Engine.pptx
How to deploy your Apps in serverless-way using App Engine.pptx
 
Migrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless PlatformMigrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless Platform
 
Serverless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about serversServerless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about servers
 
Primeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverlessPrimeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverless
 
Building APIs using Laravel - A simple approach to scale
Building APIs using Laravel - A simple approach to scaleBuilding APIs using Laravel - A simple approach to scale
Building APIs using Laravel - A simple approach to scale
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
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
 
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 ...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 

Rack middlewares - ins outs