SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
Tools for Productivity
RESTful Web Services with Mojolicious and DBIx::
                     Class
About Me
Tudor Constantin
● Perl Developer @ Evozon
● http://programming.tudorconstantin.com/
● http://stackoverflow.
  com/users/459233/tudor-constantin
● https://github.com/tudorconstantin
● http://www.linkedin.
  com/in/tudorconstantin
Content
●   Objectives
●   Solutions
●   Implementation
●   Conclusions
Objectives
● Find a way to create generic, distributed DB
  oriented applications
● One backend, multiple frontends, same
  functionality:
  ○ web
  ○ mobile
  ○ desktop
● Rapid app development for the backend
  ○   Avoid boilerplate code
  ○   Adhere to the DRY principle
  ○   Generate as much code as possible
  ○   Have a predictible API
Solutions
● Implement only the business logic in Perl
● Expose it through an API
  ○   REST
  ○   SOAP
  ○   RPC
  ○   WSDL
● Services Oriented Architecture
Solutions
Chosen one is the REST architecture:
● The simplest to implement (from server and
  client perspective)
● Uniform interface
   ○ simplifies and decouples the architecture
● Stateless - each request can be treated on a
  different machine
   ○ Horizontal scalability
Implementation
RESTful routes:

GET /api/user/1

UPDATE /api/user/5

DELETE /api/user/3
Implementation
Define Mojolicious routes:

$r->get('/api/user/:id')->to('user#show')->name('user_details');

$r->put('/api/user/:id')->to('user#update')->name('user_update');



Mojolicious routes are in a 1 to 1 correlation
with the REST ones
Implementation
Methods needed to implement for each
resource:
● list - returns a collection of resources (list of
  users)
● show - return an individual resource (1
  user)
● create - create a new resource
● delete
● update
Implementation
The above operations:
● each corresponds to a DB CRUD operation

● each can get implemented in a controller
  method

● each can be implemented in a generic way:
  ○ get parameters, do stuff, return json
Implementation - Overview
Implementation
sub update{
  my $self = shift;

 my $result_rs = $self->app->model
   ->resultset( $self->{resource} )
   ->search_rs(
       { id => $self->param('id') },
   );

 return $self->render_not_found
      if ( scalar( ( $result_rs->all ) ) == 0 );

$result_rs->update_all( $self->{_payload} );
$result_rs->result_class('DBIx::Class::ResultClass::
HashRefInflator');
  my @result = $result_rs->all();
  return $self->render_json( @result );
}
Steps for having REST
1. Create the DB tables
2. Generate the DBIx::Class models with
   DBIx::Class::Schema::Loader
   a. add the relationships between models
3. Create the controllers which inherit from the
   Base controller
4. (optional) Override the desired methods (ie -
   customize the business logic)
5. Create the routes to Mojolicious
Conclusions
● Very fast to develop
  ○ There are only 6 steps
    ■ 4 of them are, or can be, automated
● Completely DRY
  ○ define the table structure only once - when it is
    created
  ○ you write a column name only when you need to do
    something special with it (validate for example)
● Very easy to test
  ○ end to end testing can be done with simple curl
    operations
End
Sample app (with the generic controller) can be
found on github:
https://github.com/tudorconstantin/expense-
tracker

The generic controller:
https://github.com/tudorconstantin/expense-
tracker/blob/master/lib/ExpenseTracker/Cont
rollers/Base.pm

Contenu connexe

Tendances

Flux - new/old approach to building frontend
Flux - new/old approach to building frontendFlux - new/old approach to building frontend
Flux - new/old approach to building frontendBartek Witczak
 
Headless drupal + react js Oleksandr Linyvyi
Headless drupal + react js   Oleksandr LinyvyiHeadless drupal + react js   Oleksandr Linyvyi
Headless drupal + react js Oleksandr LinyvyiDrupalCamp Kyiv
 
Large Scale Vandalism Detection in Knowledge Bases: PyData Berlin 2017
Large Scale Vandalism Detection in Knowledge Bases: PyData Berlin 2017Large Scale Vandalism Detection in Knowledge Bases: PyData Berlin 2017
Large Scale Vandalism Detection in Knowledge Bases: PyData Berlin 2017Alexey Grigorev
 
WebUI - rapid UI development for EGS-CC
WebUI - rapid UI development for EGS-CCWebUI - rapid UI development for EGS-CC
WebUI - rapid UI development for EGS-CCDariusz Walczak
 
OSMC 2018 | Visualization of your distributed infrastructure by Nicolai Buchwitz
OSMC 2018 | Visualization of your distributed infrastructure by Nicolai BuchwitzOSMC 2018 | Visualization of your distributed infrastructure by Nicolai Buchwitz
OSMC 2018 | Visualization of your distributed infrastructure by Nicolai BuchwitzNETWAYS
 
Apple.combine
Apple.combineApple.combine
Apple.combinemober77
 
JavaScript Roadmap - DOM Manipulation
JavaScript Roadmap - DOM ManipulationJavaScript Roadmap - DOM Manipulation
JavaScript Roadmap - DOM ManipulationAswin Barath
 
An Introduction to MongoDB
An Introduction to MongoDBAn Introduction to MongoDB
An Introduction to MongoDBChamodi Adikaram
 
11 schema design & crud
11 schema design & crud11 schema design & crud
11 schema design & crudAhmed Elbassel
 
OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...
OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...
OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...NETWAYS
 
Locomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeLocomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeMichael Mior
 
Gdg dev fest hybrid apps your own mini-cordova
Gdg dev fest hybrid apps  your own mini-cordovaGdg dev fest hybrid apps  your own mini-cordova
Gdg dev fest hybrid apps your own mini-cordovaAyman Mahfouz
 
Ng init | EPI Sousse
Ng init | EPI SousseNg init | EPI Sousse
Ng init | EPI SousseHamdi Hmidi
 
Go bei der 4Com GmbH & Co. KG
Go bei der 4Com GmbH & Co. KGGo bei der 4Com GmbH & Co. KG
Go bei der 4Com GmbH & Co. KGJonas Riedel
 
Docker @haufe lexware tech lunch
Docker @haufe lexware tech lunchDocker @haufe lexware tech lunch
Docker @haufe lexware tech lunchHaufeLexwareRomania
 

Tendances (20)

Flux - new/old approach to building frontend
Flux - new/old approach to building frontendFlux - new/old approach to building frontend
Flux - new/old approach to building frontend
 
C# 4.0 dynamic
C# 4.0 dynamicC# 4.0 dynamic
C# 4.0 dynamic
 
Headless drupal + react js Oleksandr Linyvyi
Headless drupal + react js   Oleksandr LinyvyiHeadless drupal + react js   Oleksandr Linyvyi
Headless drupal + react js Oleksandr Linyvyi
 
DOM & Events
DOM & EventsDOM & Events
DOM & Events
 
Large Scale Vandalism Detection in Knowledge Bases: PyData Berlin 2017
Large Scale Vandalism Detection in Knowledge Bases: PyData Berlin 2017Large Scale Vandalism Detection in Knowledge Bases: PyData Berlin 2017
Large Scale Vandalism Detection in Knowledge Bases: PyData Berlin 2017
 
Lean and mean MongoDB
Lean and mean MongoDBLean and mean MongoDB
Lean and mean MongoDB
 
WebUI - rapid UI development for EGS-CC
WebUI - rapid UI development for EGS-CCWebUI - rapid UI development for EGS-CC
WebUI - rapid UI development for EGS-CC
 
OSMC 2018 | Visualization of your distributed infrastructure by Nicolai Buchwitz
OSMC 2018 | Visualization of your distributed infrastructure by Nicolai BuchwitzOSMC 2018 | Visualization of your distributed infrastructure by Nicolai Buchwitz
OSMC 2018 | Visualization of your distributed infrastructure by Nicolai Buchwitz
 
Scaling xtext
Scaling xtextScaling xtext
Scaling xtext
 
Apple.combine
Apple.combineApple.combine
Apple.combine
 
JavaScript Roadmap - DOM Manipulation
JavaScript Roadmap - DOM ManipulationJavaScript Roadmap - DOM Manipulation
JavaScript Roadmap - DOM Manipulation
 
An Introduction to MongoDB
An Introduction to MongoDBAn Introduction to MongoDB
An Introduction to MongoDB
 
11 schema design & crud
11 schema design & crud11 schema design & crud
11 schema design & crud
 
OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...
OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...
OSMC 2018 | Stream connector: Easily sending events and/or metrics from the C...
 
JavaScript | Introduction
JavaScript | IntroductionJavaScript | Introduction
JavaScript | Introduction
 
Locomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeLocomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database code
 
Gdg dev fest hybrid apps your own mini-cordova
Gdg dev fest hybrid apps  your own mini-cordovaGdg dev fest hybrid apps  your own mini-cordova
Gdg dev fest hybrid apps your own mini-cordova
 
Ng init | EPI Sousse
Ng init | EPI SousseNg init | EPI Sousse
Ng init | EPI Sousse
 
Go bei der 4Com GmbH & Co. KG
Go bei der 4Com GmbH & Co. KGGo bei der 4Com GmbH & Co. KG
Go bei der 4Com GmbH & Co. KG
 
Docker @haufe lexware tech lunch
Docker @haufe lexware tech lunchDocker @haufe lexware tech lunch
Docker @haufe lexware tech lunch
 

Similaire à Perl Tools for Productivity

RedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedis Labs
 
GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSNicolas Embleton
 
FITC presents: Mobile & offline data synchronization in Angular JS
FITC presents: Mobile & offline data synchronization in Angular JSFITC presents: Mobile & offline data synchronization in Angular JS
FITC presents: Mobile & offline data synchronization in Angular JSFITC
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with DancerDave Cross
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratiehcderaad
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBElieHannouch
 
Creating a custom API for a headless Drupal
Creating a custom API for a headless DrupalCreating a custom API for a headless Drupal
Creating a custom API for a headless DrupalExove
 
Android training day 4
Android training day 4Android training day 4
Android training day 4Vivek Bhusal
 
Thinking in Components
Thinking in ComponentsThinking in Components
Thinking in ComponentsAnton Ivanov
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo dbLawrence Mwai
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBChun-Kai Wang
 
RESTful with Drupal - in-s and out-s
RESTful with Drupal - in-s and out-sRESTful with Drupal - in-s and out-s
RESTful with Drupal - in-s and out-sKalin Chernev
 
Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018Hassan Abid
 
Extending CMS Made Simple
Extending CMS Made SimpleExtending CMS Made Simple
Extending CMS Made Simplecmsmssjg
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools Yulia Shcherbachova
 

Similaire à Perl Tools for Productivity (20)

RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
RedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis code
 
GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JS
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
FITC presents: Mobile & offline data synchronization in Angular JS
FITC presents: Mobile & offline data synchronization in Angular JSFITC presents: Mobile & offline data synchronization in Angular JS
FITC presents: Mobile & offline data synchronization in Angular JS
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Creating a custom API for a headless Drupal
Creating a custom API for a headless DrupalCreating a custom API for a headless Drupal
Creating a custom API for a headless Drupal
 
Android training day 4
Android training day 4Android training day 4
Android training day 4
 
Thinking in Components
Thinking in ComponentsThinking in Components
Thinking in Components
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
RESTful with Drupal - in-s and out-s
RESTful with Drupal - in-s and out-sRESTful with Drupal - in-s and out-s
RESTful with Drupal - in-s and out-s
 
Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018
 
Extending CMS Made Simple
Extending CMS Made SimpleExtending CMS Made Simple
Extending CMS Made Simple
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Docker tlv
Docker tlvDocker tlv
Docker tlv
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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 Processorsdebabhi2
 

Dernier (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 

Perl Tools for Productivity

  • 1. Tools for Productivity RESTful Web Services with Mojolicious and DBIx:: Class
  • 2. About Me Tudor Constantin ● Perl Developer @ Evozon ● http://programming.tudorconstantin.com/ ● http://stackoverflow. com/users/459233/tudor-constantin ● https://github.com/tudorconstantin ● http://www.linkedin. com/in/tudorconstantin
  • 3. Content ● Objectives ● Solutions ● Implementation ● Conclusions
  • 4. Objectives ● Find a way to create generic, distributed DB oriented applications ● One backend, multiple frontends, same functionality: ○ web ○ mobile ○ desktop ● Rapid app development for the backend ○ Avoid boilerplate code ○ Adhere to the DRY principle ○ Generate as much code as possible ○ Have a predictible API
  • 5. Solutions ● Implement only the business logic in Perl ● Expose it through an API ○ REST ○ SOAP ○ RPC ○ WSDL ● Services Oriented Architecture
  • 6. Solutions Chosen one is the REST architecture: ● The simplest to implement (from server and client perspective) ● Uniform interface ○ simplifies and decouples the architecture ● Stateless - each request can be treated on a different machine ○ Horizontal scalability
  • 9. Implementation Methods needed to implement for each resource: ● list - returns a collection of resources (list of users) ● show - return an individual resource (1 user) ● create - create a new resource ● delete ● update
  • 10. Implementation The above operations: ● each corresponds to a DB CRUD operation ● each can get implemented in a controller method ● each can be implemented in a generic way: ○ get parameters, do stuff, return json
  • 13.
  • 14. sub update{ my $self = shift; my $result_rs = $self->app->model ->resultset( $self->{resource} ) ->search_rs( { id => $self->param('id') }, ); return $self->render_not_found if ( scalar( ( $result_rs->all ) ) == 0 ); $result_rs->update_all( $self->{_payload} ); $result_rs->result_class('DBIx::Class::ResultClass:: HashRefInflator'); my @result = $result_rs->all(); return $self->render_json( @result ); }
  • 15. Steps for having REST 1. Create the DB tables 2. Generate the DBIx::Class models with DBIx::Class::Schema::Loader a. add the relationships between models 3. Create the controllers which inherit from the Base controller 4. (optional) Override the desired methods (ie - customize the business logic) 5. Create the routes to Mojolicious
  • 16. Conclusions ● Very fast to develop ○ There are only 6 steps ■ 4 of them are, or can be, automated ● Completely DRY ○ define the table structure only once - when it is created ○ you write a column name only when you need to do something special with it (validate for example) ● Very easy to test ○ end to end testing can be done with simple curl operations
  • 17. End Sample app (with the generic controller) can be found on github: https://github.com/tudorconstantin/expense- tracker The generic controller: https://github.com/tudorconstantin/expense- tracker/blob/master/lib/ExpenseTracker/Cont rollers/Base.pm